module ActiveAdmin::Resource::ActionItems

def action_items

Returns:
  • (Array) - The set of action items for this resource
def action_items
  @action_items ||= []
end

def action_items?

Used by active_admin Base view
def action_items?
  !!@action_items && @action_items.any?
end

def action_items_for(action, render_context = nil)

Returns:
  • (Array) - Array of ActionItems for the controller actions

Parameters:
  • action (String, Symbol) -- the action to retrieve action items for
def action_items_for(action, render_context = nil)
  action_items.select{|item| item.display_on?(action, render_context) }
end

def add_action_item(options = {}, &block)

Parameters:
  • options (Hash) -- valid keys include:
def add_action_item(options = {}, &block)
  self.action_items << ActiveAdmin::ActionItem.new(options, &block)
end

def add_default_action_items

Adds the default action items to each resource
def add_default_action_items
  # New Link on all actions except :new and :show
  add_action_item :except => [:new, :show] do
    if controller.action_methods.include?('new') && authorized?(ActiveAdmin::Auth::CREATE, active_admin_config.resource_class)
      link_to(I18n.t('active_admin.new_model', :model => active_admin_config.resource_label), new_resource_path)
    end
  end
  # Edit link on show
  add_action_item :only => :show do
    if controller.action_methods.include?('edit') && authorized?(ActiveAdmin::Auth::UPDATE, resource)
      link_to(I18n.t('active_admin.edit_model', :model => active_admin_config.resource_label), edit_resource_path(resource))
    end
  end
  # Destroy link on show
  add_action_item :only => :show do
    if controller.action_methods.include?("destroy") && authorized?(ActiveAdmin::Auth::DESTROY, resource)
      link_to(I18n.t('active_admin.delete_model', :model => active_admin_config.resource_label),
        resource_path(resource),
        :method => :delete, :data => {:confirm => I18n.t('active_admin.delete_confirmation')})
    end
  end
end

def clear_action_items!

Clears all the existing action items for this resource
def clear_action_items!
  @action_items = []
end

def initialize(*args)

initialized
Add the default action items to a resource when it's
def initialize(*args)
  super
  add_default_action_items
end