Rails 3:获取当前的名称空间? [英] Rails 3: Get current namespace?

查看:77
本文介绍了Rails 3:获取当前的名称空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用方法:layout_for_namespace我设置应用程序的布局取决于我是在前端还是后端,因为后端使用的是命名空间"admin".

using a method :layout_for_namespace I set my app's layout depending on whether I am in frontend or backend, as the backend is using an namespace "admin".

我找不到找到我是哪个命名空间的好方法,我发现的唯一方法是通过解析params [:controller]中的字符串.当然,这很容易,似乎是故障安全的,并且运行良好.但是我只是想知道是否有更好的,准备好的方法来做到这一点.有人知道吗?

I could not find a pretty way to find out which namespace I am, the only way I found is by parsing the string from params[:controller]. Of course that's easy, seems to be fail-safe and working good. But I am just wondering if there's a better, prepared, way to do this. Does anyone know?

当前我仅使用以下方法:

Currently I am just using the following method:

def is_backend_namespace?
  params[:controller].index("admin/") == 0
end

预先感谢

Arne

推荐答案

您可以使用:

self.class.parent == Admin

这篇关于Rails 3:获取当前的名称空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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