Reputation: 1433
I need to implement a before_action
callback in my application controller only for activeadmin and devise controllers. For devise controllers I can do something like:
before_action :some_callback, if: :devise_controller?
How can I do the same for activeadmin controllers? I tried to make a method like:
def active_admin_controller?
if params[:controller] =~ /^admin\//i
true
end
end
but it doesn't work. Any ideas on how to reach the desired result? Thanks ahead.
Upvotes: 2
Views: 1003
Reputation: 1470
A solution that worked for me was using the config.skip_*
.
# config/initializers/active_admin.rb
ActiveAdmin.setup do |config|
# ...
config.before_action :some_callback
end
Upvotes: 0
Reputation: 1433
I've found the solution, just had to put the conditions into an array:
before_action :some_callback, unless: [:devise_controller?, :active_admin_controller?]
also, changed active_admin_controller?
method:
def active_admin_controller?
if request.filtered_parameters['controller'] =~ /^admin\//i
true
else
false
end
end
Upvotes: 2