Link_to: confirm popups twice

This tag with rails 3

<%= link_to 'Destroy', item, :method => :delete,:confirm=>'Are you sure?' %> 

creates this html

 <a href="/news/3" data-confirm="Are you sure?" data-method="delete" rel="nofollow">Destroy</a> 

Record deleted, the problem is that the popup appears twice.

What could be the reason for this?

+49
ruby-on-rails
Dec 17 '10 at 22:52
source share
14 answers

It looks like the Javascript validation handler in rails.js is attached twice.

Could you accidentally include two copies of rails.js through duplication of the javascript_include_tag helper?

+64
Dec 17 '10 at 22:57
source share

I had the same problem and spent most of the hour on this. I found a solution in my situation, and I decided that I would share it if it helps ...

My problem was that I had

 config.assets.debug = true 

in config / environment / development.rb

Change this line to

 config.assets.debug = false 

fixed duplicate confirmation for me. I found relevant information in this rail guide for the asset conveyor . Hope this helps!

+72
Dec 14 2018-11-11T00:
source share

I used to include javascript_include_tag at the bottom of my haml-layout file.

With Rails4 and Turbolinks, it happens that:

  • Everything is OK when you first load the page (a pop-up window for confirmation appears only once)
  • Visit another page -> popup occurs twice
  • Visit another page -> popup occurs three times
  • etc.
  • until I reload the page.

I solved the problem by moving javascript_include_tag from below to <head>

+43
Aug 15 '13 at 19:48
source share

I am using Rails 4 and none of the answers worked for me, however the following worked ... I changed the line:

 <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> 

to

 <%= javascript_include_tag 'application', 'data-turbolinks-eval' => false %>. 

https://github.com/rails/turbolinks/issues/244

+3
Mar 18 '15 at 20:03
source share

Great answers here,

But if you did everything and still get these double pop-ups, and if you are working in development mode , check if you have public/assets loaded with compiled assets.

Removing public/assets/* solves the problem.

+2
Aug 24 '15 at 23:30
source share

This seems to be a bug in Rails. Apparently, the directives in application.js are not only expanded into separate files when debugging mode is enabled, but also included in application.js. I did not look at the Rails code for this, but I assume that this is because application.js is the default JavaScript file. If you rename this file to something else, say default.js, it will correctly include the files specified by the directive in debug mode, and default.js will only output JavaScript code that is only in this file. This way no duplicate code is created.

Example:

application.js

// = jquery_ujs required

Foo ();

Results in:

1) jquery_ujs.js

2) application.js with jquery_ujs and foo () content




default.js

// = jquery_ujs required

Foo ();

Results in:

1) jquery_ujs.js

2) default.js with foo ()

+1
Mar 18 '13 at 10:27
source share

I had the same problem with Rails 3.2.12, but just updating to 3.2.13 solved this problem for me.

+1
May 8 '13 at 11:52
source share

In my case (Rails 3.2.13) I had to remove rails.js to fix the same problem.

I did not explicitly refer to rails.js and did not change config.assets.debug.

0
Jun 11 '13 at 14:39
source share

In my case, jQuery loaded twice because of the line //= require_tree .

To prevent this error in application.js and application.css, I use app/assets/javascript/autorequire to create a subdirectory, and instead require_tree . I am doing require_tree ./autorequire .

So the files in app/assets/javascript and app/assets/stylesheets not included automatically / by accident. I put all my personal .css and .js files in a subdirectory, and they are included implicitly. But I can determine which files from the top path should be included and in what order.

Since I am doing this, I have never had problems with assets that were not loaded as I expect.

0
Aug 09 '13 at 18:55
source share

So for me it was because I defined deleted data, not just deleted data.

IE

data: {remote: true, ...}

instead

remote: true, data: {...}

hope this helps.

0
Oct 20 '13 at 4:25
source share

In my case, it was that the application contained both "mootools ujs" and "jquery ujs". I got rid of mootools alone, and now I see only one confirmation.

0
Jul 16 '14 at 11:59
source share

just remove the turboprops that worked for me in rails4

-one
Oct 10 '13 at 14:54
source share

Try to run

 rake assets:precompile ENV=development 

or

 rake assets:precompile ENV=production 
-2
Feb 16 '15 at 14:35
source share

Delete

 //= require jquery //= require jquery_ujs //= require_tree . 

from app/assets/javascripts/application.js . Despite the comment, it downloads these js files. This works for me.

-four
Mar 08 2018-12-12T00:
source share



All Articles