1

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.

Alex Zakruzhetskyi
  • 1,383
  • 2
  • 22
  • 43
  • Isn’t this what you’re looking for? https://stackoverflow.com/questions/13180005/modifying-basecontroller-in-rails-activeadmin-gem – inveterateliterate Dec 05 '17 at 13:03
  • Not exactly. I need to implement a callback in application controller like `before_action :some_callback, unless: :devise_controller? || :active_admin_controller?`. Sorry I didn't mention that there is `unless`, not `if`. – Alex Zakruzhetskyi Dec 05 '17 at 13:14

1 Answers1

2

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
Alex Zakruzhetskyi
  • 1,383
  • 2
  • 22
  • 43