我有一个回形针和多个图像'我实现了active_admin并且产品更新很好,但是,我不能上传或编辑多个图像,我的形式是这样的:
form :html => { :multipart => true } do |f|
f.inputs "Details" do
f.input :name
f.input :created_at, :label => "Publish Product at"
f.input :category
end
f.inputs "Images" do
f.has_many :assets do |p|
p.input :asset, :as => :file, :input_html => { :multiple => true }, :label => "Image", :hint => p.object.asset.nil? ? p.template.content_tag(:span, "No Image Yet") : p.template.image_tag(p.object.asset.url(:thumb))
p.input :_destroy, :as=>:boolean, :required => false, :label=>'Remove'
end
end
f.inputs "Content" do
f.input :description
end
f.buttons
end
和......
f.inputs "Images" do
f.has_many :assets do |p|
p.input :asset, :as => :file, :input_html => { :multiple => true }, :label => "Image", :hint => p.object.asset.nil? ? p.template.content_tag(:span, "No Image Yet") : p.template.image_tag(p.object.asset.url(:thumb))
p.input :_destroy, :as=>:boolean, :required => false, :label=>'Remove'
end
end
我想上传图片,但是当我创建一个新资产时,这个图片默认缺少图片并且没有附加正确的图片,我认为因为图片的路径上传不正确。我的资产模型是:
class Asset < ActiveRecord::Base
belongs_to :product
has_attached_file :asset, :styles => { :large => "340x330", :medium => "140x80>", :thumb => "70x70>" },
:url => "/products/:id/:style/:basename.:extension",
:path => ":rails_root/public/products/:id/:style/:basename.:extension"
end
我如何修改我的资产表格以便像我想要的那样工作?谢谢!
答案 0 :(得分:7)
解决方案
嗨,这是解决方案,关键是如何在formtastic中运行嵌套属性......
form :html => { :multipart => true } do |f|
f.inputs "Product information" do
f.input :name
f.input :description
end
f.inputs "Product images" do
f.has_many :assets do |p|
p.input :asset, :as => :file, :label => "Image",:hint => p.object.asset.nil? ? p.template.content_tag(:span, "No Image Yet") : p.template.image_tag(p.object.asset.url(:thumb))
p.input :_destroy, :as=>:boolean, :required => false, :label => 'Remove image'
end
end
f.inputs "Product details" do
f.input :category, :label => "Category", :hint => "Select one category"
f.input :height
f.input :width
f.input :depth
f.input :color, :label => "Color", :hint => "Select one color"
f.input :sku, :label => "SKU"
f.input :price
end
f.buttons
end