Skip to content

Instantly share code, notes, and snippets.

@zorab47
Last active October 12, 2022 15:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zorab47/7b762a3bec30355389bf to your computer and use it in GitHub Desktop.
Save zorab47/7b762a3bec30355389bf to your computer and use it in GitHub Desktop.
Rake task to list ActiveAdmin resource and page actions
task :active_admin_actions => :environment do
skip_resources = [ 'Dashboard' ]
namespace = ActiveAdmin.application.namespace(:admin)
pages = namespace.resources.select { |r| r.is_a? ActiveAdmin::Page }
resources = namespace.resources.select { |r| r.respond_to? :resource_class }
resource_actions =
resources.each_with_object({}) do |resource, actions|
resource_name = resource.resource_class.name
if !skip_resources.include? resource_name
actions[resource_name] = resource.defined_actions
actions[resource_name].concat resource.member_actions.map { |action| action.name }
actions[resource_name].concat resource.collection_actions.map { |action| action.name }
end
end
puts resource_actions.inspect
page_actions =
pages.each_with_object({}) do |page, actions|
page_name = page.name
if !skip_resources.include? page_name
actions[page_name] = page.page_actions + [:index]
end
end
puts page_actions.inspect
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment