Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on rails: Remote Upload A File Using AJAX

I've successfully uploaded a file using PUT and html, but is there a way to upload a file in a ajax remote_form_for ?

I've tried this to no success:

<% remote_form_for @song,:html => { :multipart => true }, :url => { :action => 'upload' } do |f| %>
like image 241
devinross Avatar asked Sep 05 '09 03:09

devinross


2 Answers

If you're using Rails 3, try the Remotipart gem. It makes AJAX style file uploads relatively painless.

http://rubygems.org/gems/remotipart

http://github.com/leppert/remotipart

like image 154
leppert Avatar answered Nov 19 '22 14:11

leppert


The standard remote_form_for doesn’t understand multipart form submission so you can't actually do this without some leg-work as indicated by yoda above.

The other way to achieve this is by using an iframe.

like image 2
Toby Hede Avatar answered Nov 19 '22 13:11

Toby Hede