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
# File 'lib/active_admin/resource_controller/collection.rb', line 47

def sort_order(chain)
  params[:order] ||= active_admin_config.sort_order
  table_name = active_admin_config.resource_table_name
  if params[:order] && params[:order] =~ /^([\w\_\.]+)_(desc|asc)$/
    chain.order("#{table_name}.#{$1} #{$2}")
  else
    chain # just return the chain
  end
end