我试图上传多个图像,但在选择多个图像后,重新提交文件,只创建一个记录。我已经查看了gorails重新上传的视频,他们通过将image_id添加到表中来显示上传。但在这里重新提交多个文件上传
他们正在使用图像模型。
有人能帮我吗?
这是我的代码:
我的型号
class Photo < ActiveRecord::Base
acts_as_votable
attachment :image
has_many :users
has_many :images
end
我的控制器参数
def photo_params
params.require(:photo).permit(:photo_title, :photo_description,:photo_caption,
:image, :image_cache_id, :remove_image,)
end
照片形式视图
<%= f.attachment_field :image, direct: true, multiple: true %>
我不能发表评论(声誉不够),但您需要更详细地阅读refile gem自述文件。您的模型和控制器没有设置为允许多个文件上传。
例如,你的强参数中应该有(image_files: [])
。。。
在您的照片模型中。。。accepts_attachments_for :images, attachment: :file
像这样的图像模型…
class Image < ActiveRecord::Base
belongs_to :photo
attachment :file
end
一切都在自述中。