【问题标题】:Can't get skip_before_filter to work with ActiveAdmin in Rails无法让 skip_before_filter 在 Rails 中与 ActiveAdmin 一起使用
【发布时间】:2012-01-17 23:31:07
【问题描述】:

我正在使用设计 gem 进行身份验证,并且在我的 ApplicationController 中有以下 before_filter:

  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:

  config.skip_before_filter :require_login

并将以下内容添加到我的管理模型文件之一,listing.rb:

ActiveAdmin.register Listing do

  controller do
    skip_before_filter :require_login
  end

end

但它似乎不起作用,即使在重新启动服务器和浏览器之后也是如此。

我做错了什么?

【问题讨论】:

    标签: ruby-on-rails devise activeadmin before-filter


    【解决方案1】:

    所以两件事:

    首先:我认为您使用 Devise 的效率很低。而不是 application_controller 上的自定义登录方法,您应该:

    class ApplicationController 
      before_filter :authenticate_user!
    end
    

    就是这样 - 其他一切正常。

    第二:Active Admin 使用不同的用户类——“admin_user”(而不是“user”)。默认情况下,您将使用以下凭据:

    email: admin@example.com 
    password: password
    

    【讨论】:

    • 使用设备 authenticate_user!方法摆脱了我的问题。谢谢!
    猜你喜欢
    • 2013-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-21
    • 1970-01-01
    相关资源
    最近更新 更多