简体   繁体   中英

ActiveAdmin Gem: Redirect user to login page if not logged in

I am working with active admin gem and it is working great. But a minor that I'm facing is whenever I manually enter a url such as:

https://www.example.com/admin/users/5 

and if the admin is not logged in then the above url page shows:

{"errors":["You need to sign in or sign up before continuing."]}

which is fine, but I want a redirection to the login page and if admin log in from the page, it should show up the desired page pointing to https://www.example.com/admin/users/5

I'm not able to figure out the redirection procedure for ActiveAdmin.

In config/initializers/active_admin.rb you have such config

config.authentication_method = :authenticate_admin_user!

then create a method named authenticate_admin_user! in the ApplicationController

def authenticate_admin_user!
  #check for current_user if not then redirect to login
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