简体   繁体   中英

Can't get skip_before_filter to work with ActiveAdmin in Rails

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

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

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.

What am I doing wrong?

So two things:

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

That's it -- everything else works.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM