upload multiple images with paperclip in rails 4?

Hello, I’m learning rails and creating a small project,

Someone could tell me how can I upload multiple images with paperclip in rails 4?

Thank you very much, I hope someone can help me.

Greetings.

C’mon, mate.

Have you at least tried to google it?

Apparently no.

I’ll give you a hand with that

http://bit.ly/1mUetID

Less time being an asshat and more time learning what the word "help"
means. And yes, I will admit by all technicality you did "help" but
by all semantics you did not help by the standards of which make you a
human.

Alright, I might have exaggerated.
Hey Eugenio Tambur, if you took my response as Jordon did, pardon me. I didn’t mean to be an asshat as he says(I’m a cool guy330.gif), but, I still reckon that by trying to find out the solution of a problem or learning anything new on your own first, will definitely be one of the best way to enhance/improve your skills/knowledge.

You want to use paperclip for handling files and rails 4 as framework. All you need is the implementation for uploading multiple images.

There are many javascript plugins out there if you want go for JS way. Following are some easy to integrate plugins:

  1. jQuery File Upload => http://blueimp.github.io/jQuery-File-Upload/
  2. Plupload => http://www.plupload.com/
    Or you can use plupload_rails3 gem https://github.com/codeodor/plupload-rails3.

Which is easy to integrate and usages Plupload gem.

Following are some links which may help you:

  1. http://5minutenpause.com/blog/2013/09/04/multiple-file-upload-with-jquery-rails-4-and-paperclip/
  2. http://ikbenbitterzoet.com/2010/09/18/multiple-file-upload-with-plupload.html
  3. http://spin.atomicobject.com/2011/10/31/upload-files-directly-to-s3-with-plupload-rails-and-paperclip/
  4. http://amgrade.com/blogs/thoughts/multiple-files-upload-rails

Regards,
Lauree
(Ruby on Rails Developer)

Paperclip supports multiple files in a single upload anyway. All you need to do is make a form on another parent model (that model should be set to `accepts_nested_attributes_for` the model you have attached your file to), add the multiple => true flag to your file field, and force the name of the file field to conform with this pattern:

  :name => 'parent_model_name[attachment_model_name][][attachment_name]

So for User has_many :avatars, accepts_nested_attributes_for :avatars and Avatar has_attached_file :image, the field would be named:

  'user[avatars_attributes][][image]'

Upload that nested form and as many Avatar objects as your form field held individual files will be magically created. No drama, no jQuery, no plugins in the browser*.

Walter

*Where by browser I mean **modern** browser.

Hi, You can use nested_form gem for the same.You would be able to add more and remove existing image.

HI

Firstly we need install paperclip, imagemagic on your machine , then we need define relation to the model suppose product and product_images. we need to define accepts_nested_attributes_for :product_images in your model then

when you create object of model we need build product object to the product_iamges model.
In your view create _form.html.erb and _product_image_fields.html.erb.
In your form.html.erb write above code


Select image*
<%= f.fields_for :product_images do |builder| %>
<%= render ‘product_image_fields’, :f => builder %>
<% end %>

<%= link_to_add_fields “Browse more image”, f, :product_images %>


And your product_images.html.erb write above code

**<%= f.file_field :photo %>

<%= f.check_box :default_image, {checked: false} %>
Default Image

 <%= link_to_remove_fields “remove”, f %>
**This code work perfectly to me...