0

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"}
Pierre Olivier Tran
  • 817
  • 1
  • 7
  • 15

2 Answers2

0

Check out the example from Remotipart's docs.

Looks like you're not passing :html => { :multipart => true } to form_for

phillyslick
  • 571
  • 6
  • 12
0

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

RailsCast 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
Breno Perucchi
  • 873
  • 7
  • 16
  • Didn't work. It worked when I replaced it by ```form_tag new_feed_path(format: :js)``` , but with two major issues: - form doesn't send file data - remotipart is not used ( I get the ```'submitted via native jquery-ujs'``` message) – Pierre Olivier Tran Aug 23 '16 at 15:39
  • if there more lines in the rails logging please add in your post. – Breno Perucchi Aug 23 '16 at 15:49