Ruby on rails 使用activeadmin使用回形针一次上载多个图像
我试图让自己上传5个图像,每个模型使用主动管理,但我似乎不知道如何做到这一点。以下是我目前的activeadmin代码:Ruby on rails 使用activeadmin使用回形针一次上载多个图像,ruby-on-rails,activeadmin,Ruby On Rails,Activeadmin,我试图让自己上传5个图像,每个模型使用主动管理,但我似乎不知道如何做到这一点。以下是我目前的activeadmin代码: ActiveAdmin.register Piece do form :html => { :enctype => "multipart/form-data" } do |f| f.inputs "Details" do f.input :name f.input :description f.input :cost
ActiveAdmin.register Piece do
form :html => { :enctype => "multipart/form-data" } do |f|
f.inputs "Details" do
f.input :name
f.input :description
f.input :cost
f.input :category
f.input :photo, :as => :file, :hint => f.template.image_tag(f.object.photo.url(:medium))
end
f.buttons
end
index do
column :id
column :name
column :cost
column :category
column :inventory_count
column :available_count
column :materials
column :created_at
default_actions
end
end
我如何一次只允许5个而不是1个呢?下面是它的工作原理:
class Piece
has_many :pictures
accepts_nested_attributes_for :pictures
end
class Picture
has_attached_file :photo
end
然后在您的活动管理表单中,您将
f.has_many :pictures do |ff|
ff.input :photo, as: :file, :hint => ff.template.image_tag(ff.object.photo.thumb.url)
ff.input :_destroy, as: :boolean
end
下面是它的工作原理:
class Piece
has_many :pictures
accepts_nested_attributes_for :pictures
end
class Picture
has_attached_file :photo
end
然后在您的活动管理表单中,您将
f.has_many :pictures do |ff|
ff.input :photo, as: :file, :hint => ff.template.image_tag(ff.object.photo.thumb.url)
ff.input :_destroy, as: :boolean
end
在您的工件模型定义中,它是否有许多:照片,或者照片是否附加到工件上?你需要先得到一张有很多照片的照片。它附有文件:照片。如果我换成has_多,会是什么样子?这是如何工作的?在你的工件模型定义中,它有很多:照片,还是照片附在工件上?你需要先得到一张有很多照片的照片。它附有文件:照片。如果我换成has_多,会是什么样子?那怎么办?