I'm using button_to with :confirm in my html_options, but no confirmation dialog is appearing (in FF & Chrome)

StackOverflow https://stackoverflow.com/questions/4192142

  •  10-10-2019
  •  | 
  •  

Question

I'm creating a button like this:

<%= button_to "Remove", { :controller => 'notes', :action => 'destroy', :note_id => @note.id },:confirm => "Are you sure?" %>

This is the output:

<form method="post" action="/notes/destroy?note_id=436"  class="button_to"><div><input data-confirm="Are you sure?" type="submit" value="Remove" /><input name="authenticity_token" type="hidden" value="zofUWrh9PllFY+2UqV2qMC9YM20Oij3e1Zvw/wEL/q8=" /></div></form>

The button works fine except there's no confirmation popup when the button is clicked. What am I doing wrong? Thanks for reading.

Was it helpful?

Solution

Are you using Rails 3.0 or above? If so include the javascript files - in the header:

<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>

Here is a good walk-through:

http://www.simonecarletti.com/blog/2010/06/unobtrusive-javascript-in-rails-3/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top