简体   繁体   中英

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

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.

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM