干净的方式进行“确认";在 Rails 4 中有条件 [英] clean way to make the "confirm" conditional in rails 4

查看:38
本文介绍了干净的方式进行“确认";在 Rails 4 中有条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 rails4 页面上有一个使用细长语法的 link_to.以下link_to

I have a link_to on my rails4 page which uses slim syntax. The following link_to

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

现在需要仅在特定条件下显示确认消息.我们如何在 rails4 中实现这一点?

is now required to only show the confirm message upon a certain condition. How do we make this happen in rails4?

我试过了:

link_to exports_path, data: { confirm: result_count > 50 ? "Are you sure?" : nil }

无论条件如何,它似乎总是显示确认..

which seems to always show the confirm regardless of the condition..

推荐答案

怎么样

link_to exports_path, data: (result_count > 50  ?  { confirm:  "Are you sure?"} : nil)

这篇关于干净的方式进行“确认";在 Rails 4 中有条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆