我使用的是Rails 4.1.6和Ruby 2.1.4。我有link_to
:
= link_to 'Delete comment', [@post, comment], :method => :delete, :confirm => "Are you sure?"
它生成一个HTML:
<a confirm="Are you sure?" data-method="delete" href="/posts/first-post/comments/26" rel="nofollow">Delete comment</a>
为什么它会生成confirm
而不是data-confirm
?
我的 application.js 包括:
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap-sprockets
//= require_tree .
我的 layouts / application.html.erb 包括:
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
答案 0 :(得分:1)
您没有指定它。试试这个
= link_to 'Delete comment', [@post, comment], :method => :delete, :data => { :confirm => "Are you sure?" }