如何使用refile上传多个图像

时间:2016-04-13 18:30:08

标签: ruby-on-rails-4 refile

我正在尝试上传多张图片,但在选择多张图片后,只能创建一条记录。我已经检查了gorails refile视频,他们通过将image_id添加到表格来上传。                                                               但是refile multiple file uploads

他们正在使用Image模型。

有人可以帮我吗?

这是我的代码:

我的模特

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 %>

1 个答案:

答案 0 :(得分:0)

我无法发表评论(声誉不够),但您需要更详细地了解refile gem README。您的模型和控制器未设置为允许多个文件上传。

例如,你的强参数应该有(image_files: []) ......

在你的照片模特中......     accepts_attachments_for :images, attachment: :file

像这样的图像模型......

  class Image < ActiveRecord::Base
    belongs_to :photo
    attachment :file
  end

全部都在自述文件中。