ajax fileupload through rails remotipart gem

Question!

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) {

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

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

Here's my form code:

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

  <fieldset>
    <legend class='required'>
      Required fields
    </legend>
      <div class="field">
        <%= f.label :name %><br />
        <%= f.file_field :name %>
      </div>
    </fieldset>
  <div class="actions">
    <%= f.submit %>
  </div>
<% 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.



Answers

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