JavierQQ23
JavierQQ23

Reputation: 714

Rails - Using ajax to upload images

I've been trying to upload an image using ajax, but maybe I'm doing it wrong

<%= simple_form_for @note, remote: true do |f|%>
  <%= f.text_area :content%>
  <%= f.file_field :picture %>
  <%= f.submit "save"%>
<%end%>

but every time I hit save... it is not doing the upload, it goes to the show action instead of displaying the alerts that I have in the file create.js.erb (it does have the multipart parameter in the form label. Is it possible to upload an image using this way? or should I check the jquery-file-upload library?

Thanks in advance

Javier

Upvotes: 4

Views: 5491

Answers (2)

Muhammad Sannan Khalid
Muhammad Sannan Khalid

Reputation: 3137

You can use jquery.form plugin for file upload through ajax. Here is a link for that.

http://jquery.malsup.com/form/

Upvotes: 2

Bjoernsen
Bjoernsen

Reputation: 2418

You can not use Ajax for a file upload. But you can use e.g. the fileupload plugin for jQuery http://blueimp.github.com/jQuery-File-Upload/

I had the same problem --> form_tag with remote: true does not make an ajax request

Upvotes: 4

Related Questions