使用rails app中的ActiveAdmin重定向管理员登录问题

时间:2018-04-04 10:54:57

标签: ruby-on-rails ruby authentication devise activeadmin

我正在使用a2 b2 c3 devise

当我以管理员身份(activeadmin)登录我的应用时,该应用会将我重定向到http://localhost:3000/users/admin页面。

所以基本上我必须登录某个用户才能以管理员身份登录。这真的很不方便。

这是我的http://localhost:3000/users/sign_in

application_controller.rb

我把这块代码添加到控制器中没有任何好运。

 class ApplicationController < ActionController::Base
       protect_from_forgery prepend: true, with: :exception

       before_action :authenticate_user!, except: [:index]

      def after_sign_in_path_for(resource)
        user_path(resource)
      end

      def after_sign_up_path_for(resource)
        user_path(resource)
      end


  before_action :configure_permitted_parameters, if: :devise_controller?

    protected

    def configure_permitted_parameters
     devise_parameter_sanitizer.permit(:sign_up, keys: [:username, :email, :password, :password_confirmation])
     devise_parameter_sanitizer.permit(:sign_in, keys: [:login, :password, :password_confirmation])
     devise_parameter_sanitizer.permit(:account_update, keys: [:username, :email, :password, :password_confirmation, :current_password])
    end


end

这是我的路线

before_action :whois, if: :devise_controller?


def whois
 if user.admin?
   def after_sign_in_path_for(resource)
     admin_dashboard_path
   end
 else
   def after_sign_in_path_for(resource)
     user_path(resource)
   end

   def after_sign_up_path_for(resource)
     user_path(resource)
   end
 end
end  

有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:0)

在初始化程序active_admin.rb中 - 试试这个

config.authentication_method = false