class ActiveAdmin::Views::IndexAsTable::IndexTableFor
Extend the default ActiveAdmin::Views::TableFor
with some methods for quickly displaying items on the index page
Public Instance Methods
Source
# File lib/active_admin/views/index_as_table.rb, line 348 def actions(options = {}, &block) name = options.delete(:name) { "" } defaults = options.delete(:defaults) { true } dropdown = options.delete(:dropdown) { false } dropdown_name = options.delete(:dropdown_name) { I18n.t "active_admin.dropdown_actions.button_label", default: "Actions" } options[:class] ||= "col-actions" column name, options do |resource| if dropdown dropdown_menu dropdown_name do defaults(resource) if defaults instance_exec(resource, &block) if block_given? end else table_actions do defaults(resource, css_class: :member_link) if defaults if block_given? block_result = instance_exec(resource, &block) text_node block_result unless block_result.is_a? Arbre::Element end end end end end
Add links to perform actions.
“‘ruby # Add default links. actions
# Add default links with a custom column title (empty by default). actions name: ‘A title!’
# Append some actions onto the end of the default actions. actions do |admin_user|
item 'Grant Admin', grant_admin_admin_user_path(admin_user) item 'Grant User', grant_user_admin_user_path(admin_user)
end
# Append some actions onto the end of the default actions using arbre dsl. actions do |admin_user|
a 'Grant Admin', href: grant_admin_admin_user_path(admin_user)
end
# Custom actions without the defaults. actions defaults: false do |admin_user|
item 'Grant Admin', grant_admin_admin_user_path(admin_user)
end
# Append some actions onto the end of the default actions displayed in a Dropdown Menu
actions dropdown: true do |admin_user|
item 'Grant Admin', grant_admin_admin_user_path(admin_user)
end
# Custom actions without the defaults displayed in a Dropdown Menu
. actions defaults: false, dropdown: true, dropdown_name: ‘Additional actions’ do |admin_user|
item 'Grant Admin', grant_admin_admin_user_path(admin_user)
end
“‘
Source
# File lib/active_admin/views/index_as_table.rb, line 294 def id_column(*args) raise "#{resource_class.name} has no primary_key!" unless resource_class.primary_key options = args.extract_options! title = args[0].presence || resource_class.human_attribute_name(resource_class.primary_key) sortable = options.fetch(:sortable, resource_class.primary_key) column(title, sortable: sortable) do |resource| if controller.action_methods.include?("show") link_to resource.id, resource_path(resource), class: "resource_id_link" elsif controller.action_methods.include?("edit") link_to resource.id, edit_resource_path(resource), class: "resource_id_link" else resource.id end end end
Display a column for the id
Source
# File lib/active_admin/views/index_as_table.rb, line 287 def index_column(start_value = 1) column "#", class: "col-index", sortable: false do |resource| @collection.offset_value + @collection.index(resource) + start_value end end
Source
# File lib/active_admin/views/index_as_table.rb, line 280 def selectable_column return unless active_admin_config.batch_actions.any? column resource_selection_toggle_cell, class: "col-selectable", sortable: false do |resource| resource_selection_cell resource end end
Display a column for checkbox
Private Instance Methods
Source
# File lib/active_admin/views/index_as_table.rb, line 376 def defaults(resource, options = {}) localizer = ActiveAdmin::Localizers.resource(active_admin_config) if controller.action_methods.include?("show") && authorized?(ActiveAdmin::Auth::READ, resource) item localizer.t(:view), resource_path(resource), class: "view_link #{options[:css_class]}", title: localizer.t(:view) end if controller.action_methods.include?("edit") && authorized?(ActiveAdmin::Auth::EDIT, resource) item localizer.t(:edit), edit_resource_path(resource), class: "edit_link #{options[:css_class]}", title: localizer.t(:edit) end if controller.action_methods.include?("destroy") && authorized?(ActiveAdmin::Auth::DESTROY, resource) item localizer.t(:delete), resource_path(resource), class: "delete_link #{options[:css_class]}", title: localizer.t(:delete), method: :delete, data: { confirm: localizer.t(:delete_confirmation) } end end