ajax fileupload through rails remotipart gem


I have been trying to upload images through remotipart and carrierwave. Simply fileupload is working fine, I have also installed remotipart gem which enables file upload through ajax.Now the issue is how to send the file through ajax(I mean the jquery part).

This is how I'm trying to send the file to my controller,but its not working

$("#upload").live("submit",function(e) {

    var report ={};
    report.file =$("#new_upload").find('#upload_name').val(); 

    $.ajax(this.action, {
        data:  report,
        iframe: true,
        processData: false
    }).complete(function(data) {

Here's my form code:

<%= form_for(@upload,:url => { :action => "save_remotipart" },:html => {:multipart => true },:remote => (params[:action] ==  true )) do |f| %>

    <legend class='required'>
      Required fields
      <div class="field">
        <%= f.label :name %><br />
        <%= f.file_field :name %>
  <div class="actions">
    <%= f.submit %>
<% end %>

When the form is submitted No parameters are sent to the server. On abort I'm getting this:

{"object Object"=>nil}

Please help me.


I had the same issue. Follow this link it might be helpfull. http://www.javaroots.com/2015/04/asynchronous-file-uploads-in-rails.html#disqus_thread

This video can help you solving your question :)
By: admin