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

- (Object) actions(options = {}, &block)

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 “`



240
241
242
243
244
245
246
247
248
249
# 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

- (Object) default_actions(*args)



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# 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

- (Object) id_column

Display a column for the id



213
214
215
216
217
218
219
220
221
# 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

- (Object) selectable_column

Display a column for checkbox



205
206
207
208
209
210
# 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