문제

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