upload multiple images with paperclip in rails 4?

458 views
Skip to first unread message

Eugeniu Tambur

unread,
Apr 28, 2014, 5:10:37 PM4/28/14
to rubyonra...@googlegroups.com
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.

Mateus Couto

unread,
Apr 29, 2014, 2:20:52 AM4/29/14
to rubyonra...@googlegroups.com
C'mon, mate.
Have you at least tried to google it?
Apparently no.
I'll give you a hand with that


Sent from my iPhone
--
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-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/57c4bc33-12ae-4e05-abdf-452b0a220164%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jordon Bedwell

unread,
Apr 29, 2014, 2:26:04 AM4/29/14
to rubyonra...@googlegroups.com
On Tue, Apr 29, 2014 at 1:20 AM, Mateus Couto <mat...@gmail.com> wrote:
> 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.

*** Mateus ***

unread,
Apr 29, 2014, 3:32:39 AM4/29/14
to rubyonra...@googlegroups.com
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 guy), 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 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-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
330.gif

Lauree Roberts

unread,
Apr 29, 2014, 11:49:59 PM4/29/14
to rubyonra...@googlegroups.com

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)

Walter Lee Davis

unread,
Apr 30, 2014, 8:38:51 AM4/30/14
to rubyonra...@googlegroups.com
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.
> --
> 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-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@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.

Sunil Kumar

unread,
May 2, 2014, 1:15:25 AM5/2/14
to rubyonra...@googlegroups.com
Hi, You can use nested_form gem for the same.You would be able to add more and remove existing image.


On Tuesday, April 29, 2014 2:40:37 AM UTC+5:30, Eugeniu Tambur wrote:

Pratap Patil

unread,
May 7, 2014, 1:42:07 AM5/7/14
to rubyonra...@googlegroups.com
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

 <div class="control-group">
      <label class = "control-label">Select image<abbr title="required">*</abbr></label>
        <%= f.fields_for :product_images do |builder| %>
          <%= render 'product_image_fields', :f => builder %>
        <% end %>
      <div class="controls">
        <%= link_to_add_fields "Browse more image", f, :product_images %></p>
      </div>
    </div>
 
And your product_images.html.erb write above code
<div>
  <%= f.file_field :photo %>

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

    <span>&nbsp;<%= link_to_remove_fields "remove", f %></span>

  </div>

 
This code work perfectly to me...


On Tuesday, April 29, 2014 2:40:37 AM UTC+5:30, Eugeniu Tambur wrote:
Reply all
Reply to author
Forward
0 new messages