在 Rails 中,如何有一个/admin 部分,然后在 admin 部分中有控制器? [英] In Rails, how to have an /admin section, and then controllers within the admin section?
问题描述
我想在我的应用程序中有一个/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屋!