Reputation: 955
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"}
Upvotes: 0
Views: 2038
Reputation: 893
try it
<%= form_tag new_feed_path, html: {multipart: true }, method: :post, remote:true do |f| %>
<%= hidden_field_tag :brief_id, @brief.id %>
<%= file_field_tag :file %>
<%= submit_tag "Send", class: "btn btn-success" %>
<% end %>
edit
try it
install this gem pry
briefs_controller.rb
def new_feed
binding.pry #just to be sure that this action is not called
puts params
respond_to do |format|
format.js { render 'new_feed') # modify this
end
end
Upvotes: 0
Reputation: 571
Check out the example from Remotipart's docs.
Looks like you're not passing :html => { :multipart => true }
to form_for
Upvotes: 0