【问题标题】:how to upload multiple images with refile如何使用 refile 上传多张图片
【发布时间】:2016-04-13 18:30:07
【问题描述】:

我正在尝试上传多张图片,但在选择多张图片后重新归档仅创建一条记录。我已经从那里查看了 gorails refile 视频,他们通过将 image_id 添加到表中显示上传。 但是这里refile multiple file uploads

他们正在使用图像模型。

谁能帮我解决这个问题?

这是我的代码:

我的模型

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

照片表单视图

&lt;%= f.attachment_field :image, direct: true, multiple: true %&gt;

【问题讨论】:

    标签: ruby-on-rails-4 refile


    【解决方案1】:

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

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

    在您的照片模型中... accepts_attachments_for :images, attachment: :file

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

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

    所有内容都在自述文件中。

    【讨论】:

      猜你喜欢
      • 2019-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-16
      • 1970-01-01
      • 1970-01-01
      • 2017-07-27
      • 2022-01-16
      相关资源
      最近更新 更多