【问题标题】:How to detect if rails is at the root url?如何检测rails是否在根url?
【发布时间】:2009-12-17 21:10:13
【问题描述】:

我想要的似乎很简单。

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

module ApplicationHelper

def isroot
if root_url 
@container = "mainbox"
else
@container = "maincontainerbox"
end
end
end

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

 <div id="<%= isroot %>">

如何确定我的应用程序是否在主页上。如果不做其他事情。

【问题讨论】:

    标签: ruby-on-rails routing


    【解决方案1】:

    测试你是否在站点根目录:

    current_page?('/')
    

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

    current_page?(root_url)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      • 2020-07-05
      相关资源
      最近更新 更多