如何检测rails是否在根url? [英] How to detect if rails is at the root url?
本文介绍了如何检测rails是否在根url?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要的似乎很简单.
在我的应用程序助手中我设置了这个
In my application helper i setup this
module ApplicationHelper
def isroot
if root_url
@container = "mainbox"
else
@container = "maincontainerbox"
end
end
end
在我的应用程序布局中我有这个
in my application layout i have this
<div id="<%= isroot %>">
如何确定我的应用程序是否在主页上.如果不做其他事情.
How do I find out if my application is at the homepage. if not do something else.
推荐答案
测试你是否在站点根目录:
To test if you are at the site root:
current_page?('/')
或者,如果您在 config/routes.rb
中定义了 map.root
:
or, if you defined map.root
in your config/routes.rb
:
current_page?(root_url)
这篇关于如何检测rails是否在根url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文