Rails Devise& ActiveAdmin单一模型路由

时间:2013-12-13 03:09:09

标签: ruby-on-rails devise activeadmin

我正在使用Devise和ActiveAdmin,我让他们通过is_admin标志共享一个users表。我的路线文件如下所示:

Site::Application.routes.draw do
  devise_for :users, ActiveAdmin::Devise.config
  ActiveAdmin.routes(self)
end

这给了我这些路线

                 Prefix Verb       URI Pattern                    Controller#Action
        new_user_session GET        /admin/login(.:format)         active_admin/devise/sessions#new
            user_session POST       /admin/login(.:format)         active_admin/devise/sessions#create
    destroy_user_session DELETE|GET /admin/logout(.:format)        active_admin/devise/sessions#destroy
           user_password POST       /admin/password(.:format)      active_admin/devise/passwords#create
       new_user_password GET        /admin/password/new(.:format)  active_admin/devise/passwords#new
      edit_user_password GET        /admin/password/edit(.:format) active_admin/devise/passwords#edit
                         PATCH      /admin/password(.:format)      active_admin/devise/passwords#update
                         PUT        /admin/password(.:format)      active_admin/devise/passwords#update
cancel_user_registration GET        /admin/cancel(.:format)        devise/registrations#cancel
       user_registration POST       /admin(.:format)               devise/registrations#create
   new_user_registration GET        /admin/sign_up(.:format)       devise/registrations#new
  edit_user_registration GET        /admin/edit(.:format)          devise/registrations#edit
                         PATCH      /admin(.:format)               devise/registrations#update
                         PUT        /admin(.:format)               devise/registrations#update
                         DELETE     /admin(.:format)               devise/registrations#destroy

我希望管理信息中心可以从/admin获得,但我希望用户管理部分可以从/users获得。因此new_user_session位于/users/login而不是/admin/login

任何人都能做到这一点吗?

2 个答案:

答案 0 :(得分:5)

事实证明,您可以通过从设计中省略ActiveAdmin来实现此目的。而不是:

Site::Application.routes.draw do
  devise_for :users, ActiveAdmin::Devise.config
  ActiveAdmin.routes(self)
end

这样做:

Site::Application.routes.draw do
  devise_for :users
  ActiveAdmin.routes(self)
end

答案 1 :(得分:0)

Active Admin本身可以配置为/生效:

# config/initializers/active_admin.rb
ActiveAdmin.setup do |config|
  config.default_namespace = false
  # ...
end

同时,可以将各个页面配置为自定义命名空间:

# app/admin/dashboard.rb
ActiveAdmin.register_page 'Dashboard', namespace: :admin do
  # ...
end