Ruby on Rails: Why the confirmation message does not appear in “link_to('delete', …)”?

空扰寡人 提交于 2020-01-03 02:10:25

问题


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.


回答1:


<%= link_to("Delete", product, :method => :delete, :class => 'action', :confirm => 'Are you sure?') %>

check your javascript_include_tag and it should work fine :)




回答2:


try adding it as a data-attribute

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




回答3:


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

javascript_include_tag :defaults


来源:https://stackoverflow.com/questions/4437991/ruby-on-rails-why-the-confirmation-message-does-not-appear-in-link-todelete

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!