11

what is the easiest way in rails 3 to to ask "Are you sure you want to do that?" when the user clicks on a link?

the link in this case overwrites some data with a new value. It's a simple link_to (GET) back to the same controller method, with a param[] added.

4

3 回答 3

24

对于像我一样来到这里但使用 Rails 4/5 的人:

link_to "Title", some_path, data: { confirm: "Are you sure?" }

文档

于 2016-03-29T14:36:00.533 回答
11

编辑:
<%= link_to "Do something", {:controller => "foo", :action => "bar"}, :confirm => "Are you sure you want to do that?" %>

于 2011-04-03T09:21:08.923 回答
5

有一个:confirm选项:

link_to "Visit Other Site", "http://www.rubyonrails.org/", :confirm => "Are you sure?"
# => <a href="http://www.rubyonrails.org/" data-confirm="Are you sure?"">Visit Other Site</a>

你应该有像这个用于 JQuery的不显眼的 JavaScript 驱动程序。设置非常简单。

详细信息在Rails API中。有关 Rails 3 中的 UJS 的更多详细信息,您可以按照本教程进行操作。

于 2011-04-03T09:28:28.870 回答