Active Admin before filter for namespace only

我与影子孤独终老i 提交于 2019-12-13 04:35:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!