• Rails: button_to with [data-confirm] tries to confirm tries and nothing happens

If you are using jquery-ujs and happens to get two confirm dialogs when using [data-confirm] with a button, all you have to do is put the data confirm attribute in a form attribute:

Before:

<%= button_to registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete do %>
    Cancel my account
<% end %>

After

<%= button_to registration_path(resource_name), form: { data: { confirm: "Are you sure?" } }, method: :delete do %>
    Cancel my account
<% end %>

The Author

Dan Schultzer is an active experienced entrepreneur, starting the Being Proactive groups, Dream Conception organization, among other things. You can find him at twitter

Like this post? More from Dan Schultzer

Comments? We would love to hear from you, write us at @dreamconception.