Module: CollectionSorter::Sorter

Extended by:
ActiveSupport::Concern
Defined in:
lib/collection_sorter/sorter.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#apply_sort(scope, default = nil) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/collection_sorter/sorter.rb', line 20

def apply_sort(scope, default=nil)
  sorter = (request.params[:sort] rescue nil) || default || (return scope)
  sorter = default unless self.sorters.include?(sorter.to_sym)

  return self.sorters[sorter.to_sym].call(scope) if sorter.present?
  scope
end