Multiple File Uploads with Paperclip & Rails 3 (Screencast)
I really *really* need to update this screencast. I've learned so much over the last year that it's embarrassing to have this public. I'm leaving this up because some people have found it useful, but I'm hoping to do a proper update soon. Perhaps I'll wait for Rails 4...
Head over to Github and grab the full source of this application. More show notes will be online soon.
-
Laen
5:37 AM on Saturday, February 19th, 2011
Thanks! This is excellent.
-
Adam21e
9:49 AM on Wednesday, March 9th, 2011
Thanks for the great screencast, much appreciated. :-)
I was wondering if you knew how to add validations to the model (eg validates :title, :presence => true) and have the attachments preserved if the title is missing so they don't need to be uploaded again.
-
David Tidwell
8:27 AM on Thursday, March 10th, 2011
Hi, just wanted to thank you for this. I watched your tutorial before, but it was back in rails 2, so I'm really excited to watch this in rails 3!
-
Chris
8:41 AM on Thursday, April 21st, 2011
How do you show these images in the views. When I do post.assets[0].url I get url is an undefined method. How else could you grab the url to generate an image with the image tag outside of the form as shown in the screencast?
-
seamusjr
9:56 PM on Sunday, August 14th, 2011
Great tutorial for adding multiple images to models with paperclip in rails 3. To answer Chris's question, you can do this in the show page to iterate through your image collection.
-
seamusjr
10:01 PM on Sunday, August 14th, 2011
To answer Chris's question, you can do this in the show page to iterate through your image collection:
https://gist.github.com/1145350 -
rmagnum2002
11:10 PM on Wednesday, September 7th, 2011
https://gist.github.com/1145350
this isn't working..
gave me an error
undefined method `assets' for nil:NilClass
Extracted source (around line #12):
9:
10:
11:
12:
...please help. thanks
-
rmagnum2002
12:46 PM on Thursday, September 8th, 2011
how can you take one asset to the index.html?
I mean display a thumb next to the post.
And how can you limit the upload files? cause I can upload 5 then edit the post and upload 5 more and so on.. ending up having more images than needed -
Emils
5:09 PM on Wednesday, September 21st, 2011
Great screencast !
But
When I try to upload an image, I get - ActiveRecord::UnknownAttributeError (unknown attribute: image).Anyone has this issue?
Any solutions ?I noticed that this app from git hub is on rails 3.0.3 (My app 3.1.0) - Could this be the case ?
Thanks!
-
Hunter Husar
1:14 AM on Thursday, October 6th, 2011
Thank you! Very great tutorial very helpful :) !
-
Gordon Yeong
8:12 AM on Monday, October 10th, 2011
thanks for doing this. I too did multi images uploads using rails 2.3.8 but with a new project on rails 3, your guide provided me opportunity to further simplify my code. On rails 2.3.8, i relied on js to dynamically create more file fields in the view but with yours, i just calculated the number of new file fields required when the 'update' message is sent to the resource controller :)
Sweet :D -
Prashanth
5:12 AM on Sunday, December 18th, 2011
Great screencast, saved my day!!
Keep them coming :)
-
Steve
1:30 AM on Wednesday, December 28th, 2011
Thanks for this screencast. VERY helpful. I seem to be having a problem with displaying the attachments in my show view. Can you email me the code you use in your show view? I appreciate your work on this topic.
-
Tony F
4:24 AM on Saturday, June 2nd, 2012
great screencast - very helpful - thanks! :D
-
Yaniv
1:15 PM on Wednesday, July 11th, 2012
Great cast!
My problem is, every image is duplicated upon create/update, that is, saved twice to the db (and afterwards displayed twice in the view as a result)
In other pages, and even in the same page as well, I also have a single upload file, which works fine.
As a rails newbie, I don't really know where to look at...
Help appreciated. -
Ariel Crippa
8:13 PM on Friday, September 14th, 2012
I have a problem to show the 5 fields file, I can not make them appear, I followed all the tutorial and I have only this error, that could be the problem?
Thanks! -
Yura
7:39 AM on Monday, October 15th, 2012
Great tut! Thanks. Is there way to update it to use one file field with html5 multiple attribute?
-
Reejo
5:52 AM on Tuesday, December 4th, 2012
I would like to suggest few modifications.
This is a really cool way to preload the images already attached to the post.
"http://stackoverflow.com/questions/10266005/updating-paperclip-avatar-in-multipart-simple-form"then in the Controller - edit method can be
(5-(@post.assests.count)).times { @post.assests.build }and in the form you can change it
:avatar,
label: "Image" %>