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, #order_for_sort_key, #sortable?, #tag_name, #visible_columns

Instance Method Details

#default_actions(options = {}) ⇒ Object

Adds links to View, Edit and Delete



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/active_admin/views/index_as_table.rb', line 149

def default_actions(options = {})
  options = {
    :name => ""
  }.merge(options)
  column options[:name] do |resource|
    links = ''.html_safe
    if controller.action_methods.include?('show')
      links << link_to(I18n.t('active_admin.view'), resource_path(resource), :class => "member_link view_link")
    end
    if controller.action_methods.include?('edit')
      links << link_to(I18n.t('active_admin.edit'), edit_resource_path(resource), :class => "member_link edit_link")
    end
    if controller.action_methods.include?('destroy')
      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
end

#id_columnObject

Display a column for the id



142
143
144
145
146
# File 'lib/active_admin/views/index_as_table.rb', line 142

def id_column
  column(resource_class.human_attribute_name(resource_class.primary_key), :sortable => resource_class.primary_key) do |resource| 
    link_to resource.id, resource_path(resource), :class => "resource_id_link"
  end
end

#selectable_columnObject

Display a column for checkbox



136
137
138
139
# File 'lib/active_admin/views/index_as_table.rb', line 136

def selectable_column
  return unless active_admin_config.batch_actions.any?
  column( resource_selection_toggle_cell, { :class => "selectable" } ) { |resource| resource_selection_cell( resource ) }
end

#status_tag(*args, &block) ⇒ Object

Display A Status Tag Column

index do |i|
  i.status_tag :state
end

index do |i|
  i.status_tag "State", :status_name
end

index do |i|
  i.status_tag do |post|
    post.published? ? 'published' : 'draft'
  end
end


184
185
186
187
188
189
190
191
# File 'lib/active_admin/views/index_as_table.rb', line 184

def status_tag(*args, &block)
  col = Column.new(*args, &block)
  data = col.data
  col.data = proc do |resource|
    status_tag call_method_or_proc_on(resource, data)
  end
  add_column col
end