class ActiveAdmin::Views::IndexAsTable::IndexTableFor

Extend the default ActiveAdmin::Views::TableFor with some methods for quickly displaying items on the index page

Public Instance Methods

actions(options = {}, &block) click to toggle source

Add links to perform actions.

“‘ruby # Add default links. actions

# Append some actions onto the end of the default actions. actions do |admin_user|

link_to 'Grant Admin', grant_admin_admin_user_path(admin_user)

end

# Custom actions without the defaults. actions defaults: false do |admin_user|

link_to 'Grant Admin', grant_admin_admin_user_path(admin_user)

end “‘

# File lib/active_admin/views/index_as_table.rb, line 240
def actions(options = {}, &block)
  options = {
    name: "",
    defaults: true
  }.merge(options)
  column options[:name] do |resource|
    text_node default_actions(resource) if options[:defaults]
    text_node instance_exec(resource, &block) if block_given?
  end
end
default_actions(*args) click to toggle source
# File lib/active_admin/views/index_as_table.rb, line 251
def default_actions(*args)
  links = proc do |resource|
    links = ''.html_safe
    if controller.action_methods.include?('show') && authorized?(ActiveAdmin::Auth::READ, resource)
      links << link_to(I18n.t('active_admin.view'), resource_path(resource), class: "member_link view_link")
    end
    if controller.action_methods.include?('edit') && authorized?(ActiveAdmin::Auth::UPDATE, resource)
      links << link_to(I18n.t('active_admin.edit'), edit_resource_path(resource), class: "member_link edit_link")
    end
    if controller.action_methods.include?('destroy') && authorized?(ActiveAdmin::Auth::DESTROY, resource)
      links << link_to(I18n.t('active_admin.delete'), resource_path(resource), method: :delete, data: {confirm: I18n.t('active_admin.delete_confirmation')}, class: "member_link delete_link")
    end
    links
  end

  options = args.extract_options!
  if options.present? || args.empty?
    actions options
  else
    links.call(args.first)
  end
end
id_column() click to toggle source

Display a column for the id

# File lib/active_admin/views/index_as_table.rb, line 213
def id_column
  column(resource_class.human_attribute_name(resource_class.primary_key), sortable: resource_class.primary_key) do |resource|
    if controller.action_methods.include?('show')
      link_to resource.id, resource_path(resource), class: "resource_id_link"
    else
      resource.id
    end
  end
end
selectable_column() click to toggle source

Display a column for checkbox

# File lib/active_admin/views/index_as_table.rb, line 205
def selectable_column
  return unless active_admin_config.batch_actions.any?
  column resource_selection_toggle_cell, class: 'selectable' do |resource|
    resource_selection_cell resource
  end
end