问题描述
我想在使用 Ruby 的 link_to 函数上添加确认消息.
I wanted to add confirmation message on link_to function with Ruby.
= link_to 'Reset message', :action=>'reset' ,:confirm=>'Are you sure?'
任何想法为什么它不起作用?
Any ideas why it's not working?
推荐答案
首先,您应该验证您的布局是否具有 jquery_ujs.最佳做法是将其包含在您的主 application.js 中:
First, you should verify that your layout have jquery_ujs.Best practice to do it by including it in your main application.js:
//= require jquery_ujs
检查您是否在布局中包含了 application.js:
Check that you included application.js in your layout:
= javascript_include_tag :application
在开发模式下,查看源 html 并验证 jquery_ujs.js 是否存在.
While, in development mode, view your source html and verify jquery_ujs.js exists.
运行您的服务器并验证您的链接标签是否具有 data-confirm 值,例如:
Run your server and verify your link tag has data-confirm value, for example:
<a href="/articles/1" data-confirm="Are you sure?" data-method="delete">
如果所有这些步骤都正确,一切都应该正常!
If all those steps are correct, everything should work!
注意:检查这个 RailsCast http://railscasts.com/episodes/136-jquery-ajax-修订版
Note: check this RailsCast http://railscasts.com/episodes/136-jquery-ajax-revised
这篇关于如何使用 link_to Ruby on rails 添加确认消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!