为什么`button tag`不会显示确认对话框?

时间:2013-01-22 02:19:36

标签: ruby-on-rails ruby-on-rails-3

这是我的代码 尽管它已经确认,但在点击时它不会显示任何对话框 为什么呢?

查看

<%= button_tag( :name => 'destroy', :class => "btn btn-danger", :confirm => 'Are you sure?') do %>
Remove
<% end %>

2 个答案:

答案 0 :(得分:8)

您需要:data => { :confirm => ... }

HTH

答案 1 :(得分:2)

您使用的是哪种版本的导轨?

弃用:confirm以支持:data => { :confirm => 'Text' }选项 https://github.com/rails/rails/commit/fc092a9cba5fceec38358072e50e09250cf58840

# I am using 3.2.11 and this works 
<%= button_tag(:name => 'destroy', :class => "btn btn-danger", :data => {:confirm => 'Are you sure?'}) do %>
Remove
<% end %>

# this will output <button name="destroy" confirm="Are you sure?" class="btn btn-danger">Remove</button>
# notice confirm is a tag attribute, which won't be picked up by javascript
<%= button_tag(:name => 'destroy', :class => "btn btn-danger", :confirm => 'Are you sure?') do %>
Remove
<% end %>

如果您不使用萤火虫,我强烈建议您使用它 https://addons.mozilla.org/en-US/firefox/addon/firebug/

在深入ruby之前,请务必检查输出HTML。