Class: ActiveAdmin::Views::IndexAsTable::IndexTableFor
- Inherits:
-
TableFor
- Object
- Arbo::HTML::Table
- TableFor
- ActiveAdmin::Views::IndexAsTable::IndexTableFor
- 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
Defined Under Namespace
Classes: TableActions
Instance Method Summary collapse
-
#actions(options = {}, &block) ⇒ Object
Add links to perform actions.
- #default_actions ⇒ Object
-
#id_column ⇒ Object
Display a column for the id.
- #index_column(start_value = 1) ⇒ Object
-
#selectable_column ⇒ Object
Display a column for checkbox.
Methods inherited from TableFor
#build, #build_table, #build_table_body, #build_table_cell, #build_table_head, #build_table_header, #column, #columns, #current_sort, #default_options, #order_for_sort_key, #sortable?, #tag_name
Instance Method Details
#actions(options = {}, &block) ⇒ Object
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 arbo 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
“‘
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
# File 'lib/active_admin/views/index_as_table.rb', line 325 def actions( = {}, &block) name = .delete(:name) { '' } defaults = .delete(:defaults) { true } dropdown = .delete(:dropdown) { false } dropdown_name = .delete(:dropdown_name) { I18n.t 'active_admin.dropdown_actions.button_label', default: 'Actions' } [:class] ||= 'col-actions' column name, do |resource| if dropdown 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? Arbo::Element end end end end end |
#default_actions ⇒ Object
285 286 287 |
# File 'lib/active_admin/views/index_as_table.rb', line 285 def default_actions raise '`default_actions` is no longer provided in ActiveAdmin 1.x. Use `actions` instead.' end |
#id_column ⇒ Object
Display a column for the id
272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/active_admin/views/index_as_table.rb', line 272 def id_column raise "#{resource_class.name} has no primary_key!" unless resource_class.primary_key column(resource_class.human_attribute_name(resource_class.primary_key), sortable: resource_class.primary_key) 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 |
#index_column(start_value = 1) ⇒ Object
265 266 267 268 269 |
# File 'lib/active_admin/views/index_as_table.rb', line 265 def index_column(start_value = 1) column '#', class: 'col-index', sortable: false do |resource| @collection.offset_value + @collection.index(resource) + start_value end end |
#selectable_column ⇒ Object
Display a column for checkbox
258 259 260 261 262 263 |
# File 'lib/active_admin/views/index_as_table.rb', line 258 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 |