无法使skip_before_filter与Rails中的ActiveAdmin一起使用 [英] Can't get skip_before_filter to work with ActiveAdmin in Rails
问题描述
我正在使用devise gem进行身份验证,并且在ApplicationController中具有以下before_filter:
I am using the devise gem for authentication and have the following before_filter in my ApplicationController:
before_filter :require_login
def require_login
unless user_signed_in? || params[:controller] == 'devise/sessions'
flash[:error] = "You must be logged in to access that page."
redirect_to new_user_session_path
end
end
我最近实施了ActiveAdmin gem,并且正在尝试使skip_before_filter适用于ActiveAdmin,以便我可以访问ActiveAdmin。我尝试了此 post 中概述的方法,并添加了以下是config / initializers / active_admin.rb:
I have recently implemented the ActiveAdmin gem and am trying to get skip_before_filter to work for ActiveAdmin, so that I can access ActiveAdmin. I have attempted the methods outlined in this post, adding the following to config/initializers/active_admin.rb:
config.skip_before_filter :require_login
,还将以下内容添加到我的一个管理模型文件中listing.rb:
and also adding the following to one of my admin model files, listing.rb:
ActiveAdmin.register Listing do
controller do
skip_before_filter :require_login
end
end
,但即使重新启动服务器和浏览器后,它似乎也不起作用。
but it doesn't seem to work, even after restarting the server and browser.
我在做什么错了?
推荐答案
有两件事:
首先:我认为您使用Devise的效率低下。代替application_controller上的自定义登录方法,您应该:
First: I think you're using Devise inefficiently. Instead of a custom login method on application_controller, you should:
class ApplicationController
before_filter :authenticate_user!
end
就是这样-一切正常。
第二个:Active Admin使用不同的用户类- admin_user(而不是 user)。默认情况下,您将使用以下凭据:
Second: Active Admin uses a different user class -- the "admin_user" (rather than "user"). By default, you'll use the following credentials:
email: admin@example.com
password: password
这篇关于无法使skip_before_filter与Rails中的ActiveAdmin一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!