This tag with rails 3
<%= link_to \'Destroy\', item, :method => :delete,:confirm=>\'Are you sure?\' %>
produces this html
This seem to be a bug in Rails. Apparently directives in application.js are not only expanded into individual files when debug mode is enabled, but they are also included in application.js. I haven't looked at the Rails code for this but assume it is due to application.js being the default JavaScript file. If you rename this file to something else, lets say default.js it will in debug mode correctly include the files specified by the directive and default.js will only output JavaScript which is only in that file. Thus not generating duplicate code.
Example:
application.js
//= require jquery_ujs
foo();
Results in:
1) jquery_ujs.js
2) application.js with jquery_ujs contents and foo()
default.js
//= require jquery_ujs
foo();
Results in:
1) jquery_ujs.js
2) default.js with foo()
I've been used to include the javascript_include_tag
at the bottom of my haml-layout-file.
With Rails4 and Turbolinks it happens that:
I solved the problem by moving the javascript_include_tag
from the bottom into <head>
I was having this same issue, and spent the better part of an hour looking into it. I found a solution in my situation, and I figured I would share it in case it helps...
My problem was that I had
config.assets.debug = true
in config/environments/development.rb
Changing that line to
config.assets.debug = false
fixed the confirmation duplication for me. I found the relevant information in this rails guide to asset pipeline. Hope it helps!
I copy this solution from another post, but this is what worked for me (rails 5)
"remove jquery_ujs from your application.js as rails_ujs is enough for later rails version."
I had included:
//= require jquery
//= require jquery-ujs
//= require rails-ujs
and after deleting it, all works fine. Solution from: Why am I getting a JQuery alert twice in Rails?
Delete:
//= require jquery
//= require jquery_ujs
//= require_tree .
from app/assets/javascripts/application.js
. Despite of been commented it loads these js files. It works for me.
Try to run either
rake assets:precompile ENV=development
or
rake assets:precompile ENV=production