Skip to content

Instantly share code, notes, and snippets.

@toidang92
Forked from zorab47/active_admin_actions.rake
Created March 12, 2016 20:42
Show Gist options
  • Save toidang92/af77a8d8566c4f6c652a to your computer and use it in GitHub Desktop.
Save toidang92/af77a8d8566c4f6c652a 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