We are using the gem remotipart on PaperSpider to allow document upload using AJAX. This allow us to upload document in the background, without full page reload.

For now, the “NewDocument” form contains a file upload form as a starting point, and we listen to the ajax success event to initialize the “React form”.

By default the format is :format => 'js'. We got a bit of trouble to find how to get a JSON response from remotipart. You need use the option data: { type: :json } when creating your form.

<%= form_for @document, html: {:class => "form", :multipart => true }, data: { type: :json }, :remote => true do |f| %>

Then in JavaScript, you can get the JSON payload from the response.

$('form').on("ajax:remotipartComplete", function(e, data) {
    var jsonDoc = JSON.parse(data.responseText);