Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip before filter with Active Admin

I am using devise and recently added active admin, which created a separate table of admin_users to keep admins.

All works fine with Active Admin when I try to log in and browse around. However, my application controller has this for general users:

before_filter :authenticate_user!, :except => [:show, :index]

Because of this, when inside the active admin interface, whenever I try to edit or delete anything, it asks me to log in. I learned that a skip_before_filter can be used inside the controller in which the before_filter needs to be excluded, however Active Admin doesn't have a controller file in the controllers folder or anywhere in my project I could look.

can anyone suggest how to make active admin ignore the application beofre_filter which I want to apply on all of the client/user facing?

like image 848
alik Avatar asked Sep 29 '11 00:09

alik


2 Answers

In config/initializers/active_admin.rb you can add the following:

config.skip_before_action :authenticate_user!

You can also use the DSL provided to modify the ActiveAdmin controller: http://activeadmin.info/docs/8-custom-actions.html#modify_the_controller

Note: For Rails versions before 5.0 you will want to use skip_before_filter.

like image 168
coreyward Avatar answered Nov 16 '22 18:11

coreyward


I couldn't get @coreyward's solution to work, but editing config/application.rb as per this Devise post and adding:

ActiveAdmin.register_page "Dashboard" do
    controller do
      skip_before_action :name_of_filter_to_skip
    end

    # Other code
end

to admin/dashboard.rb did the trick. It didn't work by just editing config/application.rb alone. Make sure to restart your server!

like image 4
Brian Avatar answered Nov 16 '22 19:11

Brian