Class: ActiveAdmin::Views::IndexAsTable::IndexTableFor

Inherits:
TableFor
  • Object
show all
Defined in:
lib/active_admin/views/index_as_table.rb

Overview

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

Defined Under Namespace

Classes: TableActions

Instance Method Summary collapse

Methods inherited from TableFor

#build, #column, #columns, #sortable?, #tag_name

Instance Method Details

#actions(options = {}, &block) ⇒ Object

Add links to perform actions.

“‘ruby # Add default links. actions

# Add default links with a custom column title (empty by default). actions name: ‘A title!’

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

item 'Grant Admin', grant_admin_admin_user_path(admin_user)
item 'Grant User', grant_user_admin_user_path(admin_user)

end

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

a 'Grant Admin', href: grant_admin_admin_user_path(admin_user)

end

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

item 'Grant Admin', grant_admin_admin_user_path(admin_user)

end

“‘



298
299
300
301
302
303
304
305
306
307
308
309
310
311
# File 'lib/active_admin/views/index_as_table.rb', line 298

def actions(options = {}, &block)
  name = options.delete(:name) { "" }
  defaults = options.delete(:defaults) { true }

  column name, options do |resource|
    insert_tag(TableActions, class: "data-table-resource-actions") do
      render "index_table_actions_default", defaults_data(resource) if defaults
      if block
        block_result = instance_exec(resource, &block)
        text_node block_result unless block_result.is_a? Arbre::Element
      end
    end
  end
end

#id_columnObject

Display a column for the id



259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/active_admin/views/index_as_table.rb', line 259

def id_column
  raise "#{resource_class.name} has no primary_key!" unless resource_class.primary_key
  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)
    elsif controller.action_methods.include?("edit")
      link_to resource.id, edit_resource_path(resource)
    else
      resource.id
    end
  end
end

#selectable_column(**options) ⇒ Object

Display a column for checkbox



251
252
253
254
255
256
# File 'lib/active_admin/views/index_as_table.rb', line 251

def selectable_column(**options)
  return unless active_admin_config.batch_actions.any?
  column resource_selection_toggle_cell, class: options[:class], sortable: false do |resource|
    resource_selection_cell resource
  end
end