简体   繁体   中英

Rails activeadmin : how to make activeadmin have redirect path for each namespace?

I've read this question and have tried it. Indeed, the resulting Routes are two different routes. In my case the code is like

devise_for: users, ActiveAdmin :: Devise.config.merge ({path:: user_belilah})
devise_for: admin_users, ActiveAdmin :: Devise.config

the code generates routes for user_belilah and admin

When I login through user_belilah route, the page is redirected to the admin path.

As I write

  config.default_namespace = :user_belilah
  config.namespace :admin do |admin|
    admin.site_title = 'Admin Site'
    admin.authentication_method = :authenticate_admin_user!
    admin.current_user_method = :current_admin_user
    admin.logout_link_path = :destroy_admin_user_session_path
    user.root_to = 'dashboard#index'
  end

  config.namespace :user_belilah do |user|
    user.site_title = 'User Site'
    user.authentication_method = :authenticate_user!
    user.current_user_method = :current_user
    user.logout_link_path = :destroy_user_session_path
    user.root_to = 'products#index'
  end

I've written default_namespace for user_belilah and create .root_to for each namespace. Then when i login, I successfully redirected to user_belilah / dashboard . When I login through route admin,again, the page is redirected to user_belilah

how to make activeadmin have two redirect paths? it seems only one of them is a redirect route

i find the answer , i just write code to override method after_sign_in_path_for in application_controller.rb like this

def after_sign_in_path_for(resource)
    if resource.class == AdminUser
      admin_dashboard_path
    elsif resource.class  == User
      root_path
    end
  end

therefore activeadmin has two kind of redirect path when we sign in

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