I have a form with multiple file_field inputs (for images) being handled by Paperclip.
On my form, once I select an file to upload I want it to immediately upload (on selection!) and show the images thumbnail (without having to submit the completed form with the submit button)
I was able to submit the whole form via ajax using the remotipart gem… but im not sure how to achieve my goal.
Can anyone help? Please let me know if code or more explanation is needed. Many thanks.
I’d approach this problem in following way.
If you need to upload multiple files via XHR, use http://github.com/valums/file-uploader. It’s a great plugin and it will suit your needs.
Once you set that up, you should create Rails controller to handle these file uploads (or use existing one). Since you are manually uploading files, you have to write upload function yourself and use paperclip to upload and connect with your Model.
Let’s say you have a model called Photo. It has attached :photo.
This is how you can do the AJAX upload of multiple files in Rails with Paperclip.