简体   繁体   English

使用回形针主动管理多个文件/图像上传

[英]Active admin multiple file/image upload with paperclip

I use Active admin and I need upload Galleries with a lot of images. 我使用Active admin,我需要上传带有大量图片的画廊。 How can I do it? 我该怎么做? My code: 我的代码:

class Gallery < ActiveRecord::Base
  belongs_to :event
  has_many :images

  attr_accessible :name, :publish, :images, :image, :images_attributes
  accepts_nested_attributes_for :images, allow_destroy: true

  validates :name, presence: true

end

class Image < ActiveRecord::Base
  belongs_to :gallery

  attr_accessible :url
  has_attached_file :url, :styles => { :medium => "300x300>", :thumb => "100x100>" }
end


ActiveAdmin.register Gallery do
    form html: { multipart: true }  do |f|
          f.inputs  do
            f.input :name
            f.input :images, as: :file, input_html: { multiple: true}
          end            
          f.buttons
    end  
end

And I have this error: 我有这个错误:

Image(#70319146544460) expected, got ActionDispatch::Http::UploadedFile(#70319105893880)

Try this: 尝试这个:

ActiveAdmin.register Gallery do
  form multipart: true do |f|
    f.inputs do
      f.input :name

      f.has_many :images do |p|
        p.input :url
      end
    end

    f.actions
  end
end

Okay, I managed to solve it: 好的,我设法解决了它:

Try to do the following: 尝试执行以下操作:

ActiveAdmin.register Gallery do
  form html: { multipart: true }  do |f|
    f.inputs  do
      f.input :name
      file_field_tag("gallery_images_url", multiple: true, name: "gallery[gallery_images_attributes][][url]")
    end            
    f.buttons
  end  
end

I got to that solution by following this blog post: http://www.tkalin.com/blog_posts/multiple-file-upload-with-rails-3-2-paperclip-html5-and-no-javascript 我通过以下博客文章得到了解决方案: http//www.tkalin.com/blog_posts/multiple-file-upload-with-rails-3-2-paperclip-html5-and-no-javascript

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

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