image upload problem with ajax

when i upload image with submit_to_remote tag it shows me nil value when i receive value of file_field in controller.

Because of javascript security, it's not possible to access local files directly, so in pure javascript/ajax you will not be able to upload a file. Fortunately, there is a workaround for this. Remember the times before ajax when everything was done behind the scenes by using a hidden Iframe? well... time for going back in time :wink:

Basically for submitting a file via javascript and an IFrame what you do is setting a hidden IFrame, and submit your form as usual (not remotely) but targetting the IFrame. This way, the form is sent as always to the server, but the user doesn't lose the navigation, since the response of the server is sent to the IFrame, which is hidden. By using javascript from the response you can then manipulate your page and send a message to the user.

There are plenty of solutions for this problem both out of rails and for rails. One that works is using "responds_to_parent" plugin ( , which makes the trick of sending javascript back to the iframe.


javier ramirez