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

Instance Method Summary collapse

Methods inherited from TableFor

#build, #build_table, #build_table_body, #build_table_cell, #build_table_head, #build_table_header, #column, #current_sort, #default_options, #is_boolean?, #order_for_sort_key, #render_data, #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|

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

# Append some actions onto the end of the default actions displayed in a Dropdown Menu actions dropdown: true do |admin_user|

item 'Grant Admin', grant_admin_admin_user_path(admin_user)

end

# Custom actions without the defaults displayed in a Dropdown Menu. actions defaults: false, dropdown: true, dropdown_name: 'Additional actions' do |admin_user|

item 'Grant Admin', grant_admin_admin_user_path(admin_user)

end

“`



281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/active_admin/views/index_as_table.rb', line 281

def actions(options = {}, &block)
  name          = options.delete(:name)     { '' }
  defaults      = options.delete(:defaults) { true }
  dropdown      = options.delete(:dropdown) { false }
  dropdown_name = options.delete(:dropdown_name) { I18n.t 'active_admin.dropdown_actions.button_label', default: 'Actions' }

  options[:class] ||= 'col-actions'

  column name, options do |resource|
    if dropdown
      dropdown_menu dropdown_name do
        dropdown_defaults(resource) if defaults
        instance_exec(resource, &block) if block_given?
      end
    else
      text_node defaults(resource) if defaults
      text_node instance_exec(resource, &block) if block_given?
    end
  end
end

#default_actionsObject



247
248
249
# File 'lib/active_admin/views/index_as_table.rb', line 247

def default_actions
  raise '`default_actions` is no longer provided in ActiveAdmin 1.x. Use `actions` instead.'
end

#id_columnObject

Display a column for the id



237
238
239
240
241
242
243
244
245
# File 'lib/active_admin/views/index_as_table.rb', line 237

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_columnObject

Display a column for checkbox



229
230
231
232
233
234
# File 'lib/active_admin/views/index_as_table.rb', line 229

def selectable_column
  return unless active_admin_config.batch_actions.any?
  column resource_selection_toggle_cell, class: 'col-selectable' do |resource|
    resource_selection_cell resource
  end
end