Active Admin认证与User认证冲突 [英] Active Admin authentication conflicting with User authentication
问题描述
Active Admin 是用于在您的应用程序中拥有管理信息中心的宝石。它使用Devise登录用户,并为管理员创建一个单独的 admin_user
模型。我的应用程序已经使用devise,并将其用户作为用户
模型。自从我开始使用活动的管理宝石之后,在我的路由文件中,以下行不断地解析为home#index,而不是用户#dashboard,即使我的用户登录。这在以前工作正常,早在登录用户被带到用户#dashboard作为根网址。
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? / code>正在检查正在登录或不登录的
admin_user
(属于Active Admin),但不是我的用户
模型,这是我需要检查的,所以当我登录到主动管理界面,我的网站root成为用户#仪表板,而不检查用户
是否是登录或不登录如何使 .authenticate?
检查正在登录的用户
而不是 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
文件中,添加: p>
In the config/initializers/devise.rb
file, add:
config.scoped_views = true
和
config.default_scope = :user #or whichever is your regular default user model
这是它,监护人检查:用户登录,而不是:admin_user
thats it, warden checks the :user for being logged in and not :admin_user
这篇关于Active Admin认证与User认证冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!