Justin D.
Justin D.

Reputation: 4976

Active Admin before filter for namespace only

I have a namespace admin. I would like to apply a before_filter only to this namespace (not the default one, which is superuser).

I can add the following code in active_admin.rb

ns.before_filter :is_subscribed?

But then, the superuser gets the filter too.

I tried adding the before_filter inside my namespace configuration :

config.namespace :admin do |ns|
  ...
  ns.before_filter :is_subscribed?
end

but Rails throws an error :

undefined method `before_filter' for #<ActiveAdmin::Namespace:0x007fa2e0f75f00>

Upvotes: 0

Views: 1329

Answers (2)

Muntasim
Muntasim

Reputation: 6786

I would have a file active_admin_extension.rb in admin directory with the content like this:

module ActiveAdmin
  class BaseController
    before_filter :make_sure_something

    private
    def make_sure_something
      if active_admin_namespace.name == :my_desired_namespace && !something_there
         #do something here
      end
    end
  end
end

Upvotes: 0

user2708672
user2708672

Reputation: 182

You could add a controller with that before_filter then in all the controllers in that namespace inherit from that controller?

Ie. AdminBaseController.

Upvotes: 1

Related Questions