Module: ActiveAdmin::ResourceController::Collection::Sorting

Included in:
ActiveAdmin::ResourceController::Collection
Defined in:
lib/active_admin/resource_controller/collection.rb

Instance Method Summary collapse

Instance Method Details

#active_admin_collectionObject (protected)



43
44
45
# File 'lib/active_admin/resource_controller/collection.rb', line 43

def active_admin_collection
  sort_order(super)
end

#sort_order(chain) ⇒ Object (protected)



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/active_admin/resource_controller/collection.rb', line 47

def sort_order(chain)
  params[:order] ||= active_admin_config.sort_order
  if params[:order] && params[:order] =~ /^([\w\_\.]+)_(desc|asc)$/
    column = $1
    order  = $2
    table  = active_admin_config.resource_table_name
    table_column = (column =~ /\./) ? column : "#{table}.#{column}"

    chain.order("#{table_column} #{order}")
  else
    chain # just return the chain
  end
end