【发布时间】:2016-09-18 14:06:26
【问题描述】:
我已经苦苦挣扎了一周,我正在尝试在 active_admin 中创建一个表单,用户可以在其中选择几张图片,添加描述和标题,然后提交他的表单以创建看起来像画廊
到目前为止,我已经使用命令创建了两个模型:
rails g model Gallery title:string description:text
rails g model Image url:text #just in case the user has LOTS of images to upload
这是我的模型现在的样子:
gallery.rb
class Gallery < ApplicationRecord
has_many :images
accepts_nested_attributes_for :images, allow_destroy: true
end
image.rb
class Image < ApplicationRecord
belongs_to :gallery
mount_uploader :image, ImageUploader #Using Carrier Wave
end
admin/gallery.rb
permit_params :title, :description, :images
form html: { multipart: true } do |f|
f.inputs do
f.input :title
f.input :description
f.input :images, as: :file, input_html: { multiple: true }
end
f.actions
end
我的问题是,即使我的“图像”表单出现,我也无法通过其他模型保存图像,我的“公共/上传”目录中没有上传任何内容,我的数据库中也没有写入任何内容.
我找不到任何有趣的互联网可以解决这个问题
请随时索取其他文件
欢迎任何帮助
【问题讨论】:
-
您可以通过更改
permit_params来解决您的问题调用(admin/gallery.rb):permit_params :title, :description, images_attributes: [:image]希望,它会有所帮助
标签: ruby-on-rails model activeadmin multi-upload