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

Inherits:
TableFor 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 Attribute Summary

Attributes inherited from Arbre::HTML::Tag

#attributes

Attributes inherited from Arbre::HTML::Element

#children, #parent

Instance Method Summary collapse

Methods inherited from TableFor

#build, #build_sortable_header_for, #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

Methods inherited from Arbre::HTML::Table

#initialize, #set_table_tag_defaults

Methods inherited from Arbre::HTML::Tag

#add_class, #build, #class_list, #class_names, #get_attribute, #has_attribute?, #id, #id!, #id=, #initialize, #remove_attribute, #remove_class, #set_attribute, #to_s

Methods inherited from Arbre::HTML::Element

#+, #<<, #add_child, #assigns, #build, builder_method, #content, #content=, #document, #each, #get_elements_by_class_name, #get_elements_by_tag_name, #helpers, #html_safe, #indent_level, #initialize, #parent?, #remove_child, #tag_name, #to_ary, #to_s, #to_str

Methods included from Arbre::Builder::BuilderMethods

#append_return_block, #build_tag, #current_dom_context, #insert_tag, #with_current_dom_context

Methods included from Arbre::Builder

#current_dom_context, #helpers, #method_missing

Constructor Details

This class inherits a constructor from Arbre::HTML::Table

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Arbre::Builder

Instance Method Details

#default_actions(options = {}) ⇒ Object

Adds links to View, Edit and Delete



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/active_admin/views/index_as_table.rb', line 124

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, :confirm => I18n.t('active_admin.delete_confirmation'), :class => "member_link delete_link"
    end
    links
  end
end

#id_columnObject

Display a column for the id



119
120
121
# File 'lib/active_admin/views/index_as_table.rb', line 119

def id_column
  column('ID', :sortable => :id){|resource| link_to resource.id, resource_path(resource), :class => "resource_id_link"}
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


159
160
161
162
163
164
165
166
# File 'lib/active_admin/views/index_as_table.rb', line 159

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