【发布时间】:2015-05-22 17:21:57
【问题描述】:
我有三个用户 - 投资者、中小企业和管理员。 我的 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。
【问题讨论】:
标签: activeadmin ruby-on-rails-4.1