Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Active admin multiple file/image upload with paperclip

I use Active admin and I need upload Galleries with a lot of images. 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)
like image 985
quatermain Avatar asked Aug 08 '12 08:08

quatermain


1 Answers

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
like image 200
Agis Avatar answered Sep 20 '22 05:09

Agis