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

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

Add links to perform actions.

# 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


176
177
178
179
180
181
182
183
184
185
# File 'lib/active_admin/views/index_as_table.rb', line 176

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) ⇒ Object



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/active_admin/views/index_as_table.rb', line 187

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_columnObject

Display a column for the id



156
157
158
159
160
# File 'lib/active_admin/views/index_as_table.rb', line 156

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



150
151
152
153
# File 'lib/active_admin/views/index_as_table.rb', line 150

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


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

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