简体   繁体   中英

Rails Devise & ActiveAdmin single model routes

I am using both Devise and ActiveAdmin, and I have them sharing a single users table via an is_admin flag. My routes file looks like this:

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

That gives me these routes

                 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

I want the admin dashboard to be available from /admin , but I want the user administration section to be available from /users . So new_user_session would be at /users/login instead of /admin/login .

Anyone accomplish this?

It turns out that you can do this by omitting ActiveAdmin from devise. Instead of this:

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

Do this:

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

Active Admin itself can be configured to live at / :

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

At the same time, individual pages can be configured to be in custom namespaces:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM