简体   繁体   English

如何使用重新上传文件上传多张图片

[英]how to upload multiple images with refile

I am trying to upload multiple images but after selecting multiple images refile creating only one record. 我正在尝试上传多张图像,但是在选择了多张图像后,重新归档仅创建了一条记录。 I have checked out gorails refile video from there they shown upload through adding image_id to table. 我从那里检查了gorails重新归档视频,他们通过将image_id添加到表中显示了上传。 But here refile multiple file uploads 但是这里重新归档多个文件上传

they are working with Image model. 他们正在使用图像模型。

Can anyone help me on this? 谁可以帮我这个事?

here is my code: 这是我的代码:

My model 我的模特

class Photo < ActiveRecord::Base acts_as_votable attachment :image has_many :users has_many :images end

My controller params 我的控制器参数

def photo_params params.require(:photo).permit(:photo_title, :photo_description,:photo_caption, :image, :image_cache_id, :remove_image,) end

Photo form view 照片表格视图

<%= f.attachment_field :image, direct: true, multiple: true %>

I can't comment ( not enough reputation ) but you need to go through the refile gem README in more detail. 我无法发表评论(信誉不足),但您需要更详细地了解refile gem自述文件。 Your models and contoller are not set up to allow multiple file uploads. 您的模型和contoller未设置为允许多个文件上传。

Eg you should have (image_files: []) in your strong parameters... 例如,您应该在强参数中包含(image_files: []) ...

In your Photo model... accepts_attachments_for :images, attachment: :file 在您的照片模型中... accepts_attachments_for :images, attachment: :file

An image model like so.... 像这样的图像模型。

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

Its all in the README. 这一切都在自述文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM