Is it possible to retrieve all the registered resources for Active Admin interface?

I have registered a lot of resources in active admin and I want to have a list of registered resources so that it can put into my dropdown box.

Possible to do that?

有帮助吗?

解决方案

i guarantee there must be a cleaner way, but you can access your Models that have been added as to AA by accessing the resources collection in the namespace you have defined. For example, if you have AA defined in the :admin namespace

 > ActiveAdmin.application.namespace(:admin).resources.select {|r| r.respond_to? :resource_class_name}.map(&:resource_class_name) 

will produce and array of class names..

=> ["::Activity", "::ActivityType", "::AdminUser"]

that gives you a list of items you can massage into a dropdown.

其他提示

# I came up with this to generate a hash of
# :namespace => array of arrays containing 2 elements
# [title, link]
#
# With this <strikethrough>it should be trivial to</strikethrough> you can
# create a clickable select.

Hash[*
  ActiveAdmin.
  application.
  namespaces.
  collect{ |ns,v| [  
    ns, 
    v.resources.
        keys.
        select { |k|
            r = ActiveAdmin.application.namespaces[ns].resources.find_by_key(k)
            r.respond_to?(:resource_class_name) && !r.belongs_to?
        }.

        collect{|k|
          [
            k, 
            begin
              Rails.application.routes.url_helpers.send(
                ( 
                  "#{ns}_" + 
                  k.underscore.pluralize.gsub('/','_') + 
                  "_index_path"
                ).to_sym
              ) 
            rescue
              Rails.application.routes.url_helpers.send(
                ( 
                  "#{ns}_" + 
                  k.underscore.pluralize.gsub('/','_') + 
                  "_path"
                ).to_sym
              )
            end
          ]
        } 
  ]}.
  flatten(1)
]
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top