在 Rails 中,如何有一个/admin 部分,然后在 admin 部分中有控制器? [英] In Rails, how to have an /admin section, and then controllers within the admin section?

查看:29
本文介绍了在 Rails 中,如何有一个/admin 部分,然后在 admin 部分中有控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程序中有一个/admin 部分,并且在这个/admin 部分中有如下路由:

I want to have a /admin section in my application, and have routes within this /admin section like:

www.example.com/admin/(只有某些用户可以访问此部分)

www.example.com/admin/ (only certain users have acess to this section)

然后在此部分中使用控制器,例如:

then have controllers in this section like:

/admin/users/{add, new, etc}

对于这样的事情,我有什么选择?(使用导轨 3)

What are my options for something like this? (using rails 3)

推荐答案

在你的 routes.rb 中做这样的事情:

Do something like this in your routes.rb:

  namespace :admin do
    resources :users
  end

有关详细信息,请参阅 http://guides.rubyonrails.org/routing.html.

See http://guides.rubyonrails.org/routing.html for more detail.

然后在每个管理控制器中你需要一个 before_filter:

Then in each admin controller you'll need a before_filter:

before_filter :authorized?
def authorized?
    #check if authorized here.
end

这篇关于在 Rails 中,如何有一个/admin 部分,然后在 admin 部分中有控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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