link_to :confirm displays popup twice

2020-01-27 02:49发布

This tag with rails 3

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

produces this html

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

The entry is deleted, the problem is that the popup appears twice.

What could be causing this?

16条回答
甜甜的少女心
2楼-- · 2020-01-27 03:20

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

查看更多
smile是对你的礼貌
3楼-- · 2020-01-27 03:21

Great answers here,

But if you did everything and still get those double popups, and if you are running in development mode, check if you have public/assets loaded with compiled assets.

Deleting public/assets/* solves the issue.

查看更多
Viruses.
4楼-- · 2020-01-27 03:22

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:

  • Everything ok on the first load of a page (popup for confirmation appears only once)
  • Visiting another page -> popup occurs twice
  • Visiting one more page -> popup occurs three times
  • and so on
  • until I reload the page.

I solved the problem by moving the javascript_include_tag from the bottom into <head>

查看更多
Evening l夕情丶
5楼-- · 2020-01-27 03:25

Try to run either

rake assets:precompile ENV=development 

or

rake assets:precompile ENV=production
查看更多
我命由我不由天
6楼-- · 2020-01-27 03:27

It sounds like the confirmation handler Javascript in rails.js is being attached twice.

Could you be accidentally including two copies of rails.js via duplication of a javascript_include_tag helper?

查看更多
何必那么认真
7楼-- · 2020-01-27 03:27

I've had the same problem with Rails 3.2.12, but simply updating to 3.2.13 solved that problem for me.

查看更多
登录 后发表回答