2013-01-22 34 views
3

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

查看

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

add:method =>:delete – GeekToL

+0

确保javascript位于资产管道中....这已经让我在之前。 –

回答

8

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

HTH

+0

谢谢,这是它! – HUSTEN

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。