在route.rb中的ROR 3条件 [英] ROR 3 conditions in routes.rb

查看:89
本文介绍了在route.rb中的ROR 3条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在route.rb中指定条件语句-我希望root_path取决于用户是否登录.也许还有其他方法可以做到这一点?

Is there a way to specify conditional statement inside routes.rb - I would like the root_path to depend on whether the user is signed in or not. perhaps there are other ways of accomplishing this?

谢谢!

推荐答案

实际上,我认为您可以使用高级约束对其进行记录,

Actually I think you can using advanced constraints it is documented here...

您将定义一个def matches?(request)来检查用户是否已登录,并使用两种路由:一种是在有登录约束时使用,另一种是在未登录时约束. 尽管我不确定执行自定义约束时会话是否可用.

You would define a def matches?(request) to check if the user is signed in, and use two routes one when with a constraint of signed in and one when not. Although I am not sure if the session is available when that custom constraint is executed.

尽管我同意SpyrosP,但最好在Controller中做到这一点.

Although I agree with SpyrosP it would be better to do it in the Controller.

这篇关于在route.rb中的ROR 3条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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