简体   繁体   中英

Rails 3: submit_tag does not :confirm (while link_to does)

Why does this correctly launch the "confirm" dialog...

<%= link_to "Visit Other Site", "http://www.rubyonrails.org/", :confirm => "Are you sure?" %>

...but not this one:

<%= submit_tag "Save", :confirm => "Are you sure?" %>

I'm using:

  • Rails 3.2.12
  • gem 'jquery-rails' (version: 2.2.1)

The :confirm option is deprecated, it is now going to be replaced by the data attribute. Internally, the submit_tag is already doing the replacement.

See the submit_tag documentation and source code .

Because the data attributes rely on Unobtrusive JavaScript to be executed, you should have included jQuery JS and the Rails UJS file. Otherwise, the attribute will be visible in the source code (please check it) but will not trigger the confirmation.

这是一个悬而未决的问题/错误,请参见上面的评论。

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