如何检测rails是否在根URL上? [英] How to detect if rails is at the root url?

查看:68
本文介绍了如何检测rails是否在根URL上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的东西似乎很简单。

What I want is seems simple.

在我的应用程序帮助程序中,我对此进行了设置

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屋!

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