Skip to content Skip to sidebar Skip to footer

Rails Paperclip And Ajax Form

I have a modal containing a form, in which the user can upload a photo. Once the photo is correctly uploaded I want to respond via Ajax and display a message. Unfortunately the for

Solution 1:

You can't upload a file with AJAX. It's probably the reason why the submit is in HTML and not in JS.

Nevertheless you have some hack to solve this problem:

I hope this help

Solution 2:

Unfortunately rails cannot upload files directly with ajax, as javascript does not have direct access to to hard drive files. Apparently there's a workaround involving iframes: this previous question may help you:

RAILS - paperclip don't work with Ajax

and a bit on file uploading in rails forms:

http://guides.rubyonrails.org/form_helpers.html#dealing-with-ajax

Post a Comment for "Rails Paperclip And Ajax Form"