Class: ArPagination::Helpers::Sort
- Inherits:
-
Object
- Object
- ArPagination::Helpers::Sort
- Defined in:
- lib/ar_pagination/helpers/sort.rb
Instance Method Summary collapse
-
#initialize(scope) ⇒ Sort
constructor
A new instance of Sort.
- #sort(sort) ⇒ Object
Constructor Details
#initialize(scope) ⇒ Sort
Returns a new instance of Sort.
4 5 6 |
# File 'lib/ar_pagination/helpers/sort.rb', line 4 def initialize(scope) @scope = scope end |
Instance Method Details
#sort(sort) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ar_pagination/helpers/sort.rb', line 8 def sort(sort) order_hash = {} = sort.split(',') if sort Array.wrap().each do |order_option| case order_option.first when '-' direction = :desc when '+' direction = :asc else next end sort_attr = order_option[1..-1] order_hash[sort_attr.to_sym] = direction end @scope = @scope.order(order_hash) unless order_hash.empty? @scope end |