简体   繁体   中英

Enabling Async file uploads with jQuery File Upload + Carrierwave + Rails 4

I'm trying to allow users to move around the portal when the file uploads are happening.

This is my form code:

<%= form_for [@myfolder, Myfile.new], html: { multipart: true, :id => "fileupload" }, :remote => true, do |f| %>
<%= f.file_field :attachment, multiple: true, style: "display:none;" %>
<% end %>

It is hitting the create action (POST), which is responding with the JSON output.

format.html { redirect_to @parentfolder, notice: 'Your file was successfully created.' }
format.js
format.json{ render :show, status: :created, location: @myfile }

Here's the jquery file uploads call in my application.js:

add: function(e, data) {
     data.context = $(tmpl("template-upload",data.files[0]))
     $('#fileupload').append(data.context)
     $('#inline-upload-status').show();
     $.getJSON('/myfiles.json', function (result) {
        data.formData = result; // e.g. {id: 123}
        data.submit();
     });
  }

I'm not able to figure out what's wrong with this code. The file uploads are not happening.

您为什么不尝试这种宝石remotipart呢

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM