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条回答
你好瞎i
2楼-- · 2020-01-27 03:43

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!

查看更多
来,给爷笑一个
3楼-- · 2020-01-27 03:43

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.

查看更多
来,给爷笑一个
4楼-- · 2020-01-27 03:44

I'm 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

查看更多
贼婆χ
5楼-- · 2020-01-27 03:44

So for me it was because i had defined data-remote instead of just remote.

IE

data: { remote: true, ... }

instead of

remote: true, data: { ... }

hope that helps.

查看更多
登录 后发表回答