简体   繁体   English

ActiveAdmin Gem:如果未登录,则将用户重定向到登录页面

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

I am working with active admin gem and it is working great. 我正在使用主动管理的gem,它工作得很好。 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 很好,但是我想重定向到登录页面,如果管理员从该页面登录,它应该显示指向https://www.example.com/admin/users/5的所需页面

I'm not able to figure out the redirection procedure for ActiveAdmin. 我无法弄清楚ActiveAdmin的重定向过程。

In config/initializers/active_admin.rb you have such config 在config / initializers / active_admin.rb中,您有这样的配置

config.authentication_method = :authenticate_admin_user!

then create a method named authenticate_admin_user! 然后创建一个名为authenticate_admin_user的方法! in the ApplicationController 在ApplicationController中

def authenticate_admin_user!
  #check for current_user if not then redirect to login
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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