Ruby on Rails: Why the confirmation message does n

2019-06-03 01:12发布

I have the following link next to one of my products:

<%= link_to("Delete", {:action => 'destroy', :id => product.id}, :class => 'action', :confirm => 'Are you sure?') %>

but when I click it, the confirmation box does not appear.

The generated HTML is:

<a data-confirm="Are you sure ?" class="action" href="/products/destroy/48">Delete</a>

Please advise.

3条回答
ら.Afraid
2楼-- · 2019-06-03 01:25
<%= link_to("Delete", product, :method => :delete, :class => 'action', :confirm => 'Are you sure?') %>

check your javascript_include_tag and it should work fine :)

查看更多
聊天终结者
3楼-- · 2019-06-03 01:36

Ensure rails.js is being loaded on the page. The easiest way to accomplish this is with:

javascript_include_tag :defaults
查看更多
欢心
4楼-- · 2019-06-03 01:40

try adding it as a data-attribute

data: { confirm: "Are you sure?" }

查看更多
登录 后发表回答