主动管理员身份验证与用户身份验证冲突 [英] Active Admin authentication conflicting with User authentication
问题描述
Active Admin 是用于在您的应用程序中拥有管理仪表板的 gem.它使用 Devise 来登录用户并为管理员创建一个单独的 admin_user
模型.我的应用程序已经使用 devise 并将其用户作为 user
模型.自从我开始使用活动管理 gem 以来,在我的路由文件中,即使我的用户已登录,以下行仍然解析为 home#index 而不是 users#dashboard.这曾经在登录用户被带到用户的情况下工作得很好#dashboard 作为根 url.
Active Admin is a gem used for having an admin dashboard in your application. It uses Devise for logging in users and creates a separate admin_user
model for the admins. My application already uses devise and has its users as the user
model. Ever since I started using the active admin gem, in my routes file the following line keeps resolving to home#index and not users#dashboard even when my user is logged in. This used to work fine earlier where logged in users were taken to users#dashboard as the root url.
root :to => 'users#dashboard', :constraints => lambda {|r| r.env["warden"].authenticate? }
root :to => 'home#index'
发生的事情是 .authenticate?
正在检查 admin_user
(属于 Active Admin)是否登录,但不是我的 user
模型,这是我需要检查的,所以当我登录到活动管理界面时,我的站点根目录变为 users#dashboard 而不是检查 user
是否已登录.如何使 .authenticate?
检查正在登录的 user
而不是 admin_user
?
What is happening is that the .authenticate?
is checking for the admin_user
(belonging to Active Admin) being logged in or not but not my user
model which is what I need to check for, so when I am logged in to active admin interface, my site root becomes users#dashboard instead without checking if the user
is logged in or not. How can I make .authenticate?
check for the user
being logged in and not admin_user
?
非常感谢任何帮助或线索
Any help or clues will be very much appreciated
推荐答案
我能够解决这个问题.该问题与 Devise 期望应用程序中的单个用户模型有关.这是修复它的方法.
I was able to solve this. The issue was related to Devise expecting a single user model in the application. Here is how to fix it.
在config/initializers/devise.rb
文件中,添加:
config.scoped_views = true
和
config.default_scope = :user #or whichever is your regular default user model
就是这样,监狱长检查 :user 是否已登录,而不是 :admin_user
thats it, warden checks the :user for being logged in and not :admin_user
这篇关于主动管理员身份验证与用户身份验证冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!