2013-01-22 73 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。