ruby on rails - form_tag with remote: true does not make an ajax request -


i have many different forms in app, of them using remote: true. 1 not work correctly, because not use ajax call.

cleaned up, looks like:

<%= form_tag(upload_file_ajax_path, remote: true, multipart: true) %> <%= file_field_tag(:file) %> <%= submit_tag("upload") %> <%end%> 

the tag looks like:

<form accept-charset="utf-8" action="/mycontroller/upload_file_ajax" data-remote="true" enctype="multipart/form-data" method="post"> <input name="utf8" type="hidden" value="✓"> <input name="authenticity_token" type="hidden" value="1234"></div> <input id="file" name="file" type="file"> <input name="commit" type="submit" value="upload"> </form> 

and routes entry:

post "mycontroller/upload_file_ajax", as: "upload_file_ajax" 

but checking call in chrome dev tools, header says:

accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 

and not other forms like:

accept:*/*;q=0.5, text/javascript, application/javascript, application/ecmascript, application/x-ecmascript 

i added js files layout

<%= stylesheet_link_tag "application", :media => "all" %> <%= javascript_include_tag "application" %> <%= csrf_meta_tags %> 

and if remove js code out of application.js file (except //= require jquery...), form not working correctly.

what did miss?

you can't use ajax file uploads. is, normally.

there awesome gem, remotipart, adds functionality remote forms though.

gem 'remotipart', '~> 1.0' 

in application.js

//= require jquery.remotipart 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

c++ - Accessing inactive union member and undefined behavior? -

php - Get uncommon values from two or more arrays -