Rails unknown format on AJAX

Question!

I'm trying to implement a very simple file form using the remotipart gem. Most of my files are the exact same as the tutorial ones:

timeline.html.erb :

<%= form_tag new_feed_path(:format => "js"), remote: true, :html => { :multipart => true } do |f| %>
  <%= hidden_field_tag :brief_id, @brief.id %>
  <%= file_field_tag :file %>
  <%= submit_tag "Send", class: "btn btn-success" %>
<% end %>

briefs_controller.rb

 def new_feed
    puts params
    respond_to do |format|
      format.js
    end
 end

new_feed.js.erb

alert('success!');

<% if remotipart_submitted? %>
  alert('submitted via remotipart')
<% else %>
  alert('submitted via native jquery-ujs')
<% end %>

But everytime I submit the form, I get the following error in the logs:

Processing by ResourcesController#create as HTML
Completed 406 Not Acceptable in 14ms
ActionController::UnknownFormat - ActionController::UnknownFormat:

Did I miss something ? I know ajax file upload can be tricky on RoR, but remotipart seems to be a viable solution.

EDIT I managed to fix the first issue by adding :format => "js" , but now I face another problem: none of the form datas are sent. In fact, here are the sent params:

{"controller"=>"briefs", "action"=>"new_feed"}


Answers

Check out the example from Remotipart's docs.

Looks like you're not passing :html =



try it



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