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

Constant Summary

Constants included from Arbre::HTML

Arbre::HTML::AUTO_BUILD_ELEMENTS, Arbre::HTML::HTML5_ELEMENTS

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_html

Methods inherited from Arbre::HTML::Element

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

Methods included from Arbre::HTML::BuilderMethods

#build_tag, #current_dom_context, #insert_tag, #insert_text_node_if_string, #with_current_dom_context

Methods included from Arbre::HTML

#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::HTML

Instance Method Details

#default_actions(options = {}) ⇒ Object

Adds links to View, Edit and Delete



108
109
110
111
112
113
114
115
116
117
118
# File 'lib/active_admin/views/index_as_table.rb', line 108

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

#id_columnObject

Display a column for the id



103
104
105
# File 'lib/active_admin/views/index_as_table.rb', line 103

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


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

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