问题
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>
回答1:
You could add a controller with that before_filter then in all the controllers in that namespace inherit from that controller?
Ie. AdminBaseController.
回答2:
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
来源:https://stackoverflow.com/questions/18409824/active-admin-before-filter-for-namespace-only