Why doesn't the `button tag` display a confirmation dialog?

This is my code.
Even though he confirmed it, it won't show dialogue when he clicked.
Why?

View

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

      

+3


source to share


2 answers


You need :data => { :confirm => ... }



NTN

+8


source


Which version of rails are you using?

Revert :confirm

in favor of option :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 %>

      



If you are not using firebug, I highly recommend that you use it.
https://addons.mozilla.org/en-US/firefox/addon/firebug/

Always check the output HTML before diving into ruby.

+2


source







All Articles