我有三个用户 - 投资者,服务员和管理员。 我的application_controller.rb
中有以下代码class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
devise_group :person, contains: [:investor,:sme]
before_action :authenticate_person!
before_action do |controller|
redirect_to root_path if devise_controller? && person_signed_in?
end
end
现在问题是当我登录管理面板时,我被重定向回投资者登录页面。这是服务器日志
Started GET "/admin" for 127.0.0.1 at 2015-05-22 22:40:14 +0530
Processing by Admin::DashboardController#index as HTML
Completed 401 Unauthorized in 4ms
Started GET "/investors/sign_in" for 127.0.0.1 at 2015-05-22 22:40:14 +0530
Processing by Investors::SessionsController#new as HTML
Rendered investors/shared/_links.html.erb (4.0ms)
Rendered investors/sessions/new.html.haml within layouts/application (48.0ms)
Completed 200 OK in 2537ms (Views: 2532.5ms | ActiveRecord: 0.0ms)
无论身份验证成功与否,我都会被重定向到投资者登录页面。
此外,当我作为投资者或涂料登录时,我能够访问管理页面。 Activeadmin显然让我的普通用户与管理员用户混淆。这是我的config / initializers / active_admin.rb文件
ActiveAdmin.setup do |config|
config.authentication_method = :authenticate_admin_user!
config.current_user_method = :current_admin_user
config.logout_link_path = :destroy_admin_user_session_path
end
我尝试将config.skip_before_action :authenticate_person!
添加到我的active_admin.rb文件中,认为我的application_controller中的before_action :authenticate_person!
可能导致问题,但是它会引发错误undefined method devise_group for application controller
。
答案 0 :(得分:2)
我认为..我必须在app / admin / dashboard.rb文件中添加以下代码
controller do
skip_before_filter :authenticate_person!
end
尝试在config / initializers / active_admin.rb中添加config.skip_before_filter :authenticate_person!
,但导致错误undefined method devise_group for application controller
。
即使这样可行,当我以普通用户身份登录时尝试访问/ admin / login页面时,我得到一个重定向循环。
希望这可以帮助那些被困的人