Ruby on Rails Wednesday, April 30, 2014

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.

On Apr 29, 2014, at 11:49 PM, Lauree Roberts wrote:

> 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:
>
> * jQuery File Upload => http://blueimp.github.io/jQuery-File-Upload/
> * 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:
>
> * http://5minutenpause.com/blog/2013/09/04/multiple-file-upload-with-jquery-rails-4-and-paperclip/
> * http://ikbenbitterzoet.com/2010/09/18/multiple-file-upload-with-plupload.html
> * http://spin.atomicobject.com/2011/10/31/upload-files-directly-to-s3-with-plupload-rails-and-paperclip/
> * http://amgrade.com/blogs/thoughts/multiple-files-upload-rails
>
> Regards,
> Lauree
> (Ruby on Rails Developer)
>
>
>
> On Tuesday, April 29, 2014 2:40:37 AM UTC+5:30, Eugeniu Tambur wrote:
> 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.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/aee138a6-0112-4fee-8168-2781bd420666%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/D45FEAEC-B579-4E2B-849B-1B690A1538AC%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment