Skip before filter with Active Admin
Solution 1
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
.
Solution 2
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!
Solution 3
both of the corey and Sooie are right... but only partially, to stop your blanket authorize_user! filter from affecting active_admin you need to implement both of their answers...
config/initializers/active_admin.rb
config.skip_before_filter :authorize_user!
app/admin/dashboard.rb
controller do
skip_before_filter :authorize_user!
end
Solution 4
I couldn't make the solutions of @fringd and @coreyward to work on Rails4 (using ActiveAdmin master branch).
So, I've moved the filter methods (I have two filters: authorize_user!
and check_user_status
) to a new Concern, and included this created module into the Controllers which had those filters (except for the ApplicationController
, which should remain clean).
Then restarted the server, and problem solved.
alik
Updated on June 04, 2022Comments
-
alik almost 2 years
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?
-
John over 12 yearsFor some reason, the line in the initializers file is not working for me. And I am not sure. . in which files do you add the code to modify the ActiveAdmin controller?
-
coreyward over 12 years@John Make sure you restart your app after changing any initializer, and you can use the controller-modifying DSL inside the admin definition files (i.e. app/admin/post.rb).
-
John over 12 years@coreyward, couldn't get it to work, posted a new question: stackoverflow.com/questions/8903176/…
-
coreyward over 12 yearsLooks like it wasn't related to ActiveAdmin so much as Devise. Glad you got it figured out. :)
-
fringd over 11 yearsthe documentation says that the config step adds the configuration to all of your RESOURCE controllers, so the dashboard is apparently excepted from that list... going directly to /admin/some_resouce still skips things for me... so you are right, this is needed in addition to coreyward's solution
-
Koen. about 10 yearsWhy should you implement both?
-
sixty4bit over 9 yearsI'm trying to call
config.skip_after_filter
but am getting:undefined method 'skip_after_filter' for #<ActiveAdmin::Application:0x007fa445d5c898
-
Raju akula about 9 yearsFor me also, adding skip before filter not working and restarted also. am using the rails 3.2.14 and activeadmin gem.
-
Raju akula about 9 yearsBut doing below, have turn off the authentication,
config.authentication_method = false config.current_user_method = false
-
Besi about 8 yearsCan you please add code to those concern you described
-
S.Yadav over 5 yearsWorked for me! rails v -5.2.