Rails 3:如何在单击链接时显示警告消息?

发布于 2024-10-21 08:27:56 字数 238 浏览 2 评论 0原文

我的 Rails 3 应用程序中有以下链接:

link_to("Invoice", "/jobs/#{job.id}/invoice") 

当用户单击它时,应用程序会显示一张发票。

我想在缺少 job.price 时显示一条警告消息,询问用户是否继续。然后,仅当用户选择“是”时,才应将其重定向到发票页面。

实现这个最简单的方法是什么?

I have the following link in my Rails 3 application:

link_to("Invoice", "/jobs/#{job.id}/invoice") 

When user clicks it, the application shows an invoice.

I would like to display a warning message when job.price is missing, asking the user whether to continue or not. Then, it should be redirected to the invoice page only if user chose "yes".

What is the easiest way to implement this ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

荒芜了季节 2024-10-28 08:27:56

这对我有用:

link_to("Invoice", "/jobs/#{job.id}/invoice", 
        :confirm => (job.price ? '' : "Job Price is missing. Continue anyway ?")) 

This worked for me:

link_to("Invoice", "/jobs/#{job.id}/invoice", 
        :confirm => (job.price ? '' : "Job Price is missing. Continue anyway ?")) 
你不是我要的菜∠ 2024-10-28 08:27:56

试试这个

<%= link_to "Invoice", "/jobs/#{job.id}/invoice", :onclick => "#{ "confirm('The job price is missing, are you sure you want to continue?')" if job.price.nil? } %>

希望这就是您正在寻找的。祝你好运!

Try this

<%= link_to "Invoice", "/jobs/#{job.id}/invoice", :onclick => "#{ "confirm('The job price is missing, are you sure you want to continue?')" if job.price.nil? } %>

Hope that's what you are looking for. Good luck!

青丝拂面 2024-10-28 08:27:56

假设使用 Prototype.js,最简单的事情可能是内联点击处理程序。内置的 :confirm 选项将不起作用,因为您需要检查页面上的字段。

link_to("Invoice", "/jobs/#{job.id}/invoice", :onclick => "if($F('job_price') == '') confirm('Job price is not set. Are you sure you want to continue?');")

可能有一百种更复杂的方法来处理这个问题,无论是不引人注目的还是其他的。

Assuming Prototype.js, the easiest thing would probably be an inline click handler. The built-in :confirm option won't work since you need to check a field on the page.

link_to("Invoice", "/jobs/#{job.id}/invoice", :onclick => "if($F('job_price') == '') confirm('Job price is not set. Are you sure you want to continue?');")

There are probably a hundred more sophisticated ways of handling this, unobtrusively or whatever.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文