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

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

问题描述

我想要的似乎很简单.

在我的应用程序助手中,我设置了这个

module ApplicationHelper定义根目录如果 root_url@container = "主箱"别的@container = "maincontainerbox"结尾结尾结尾

在我的应用程序布局中,我有这个

 

我如何知道我的申请是否在主页上.如果不做别的事情.

解决方案

要测试您是否在站点根目录:

current_page?('/')

或者,如果您在 config/routes.rb 中定义了 map.root:

current_page?(root_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?('/')

or, if you defined map.root in your config/routes.rb:

current_page?(root_url)

这篇关于如何检测 rails 是否在根 url 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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