Class: WillSortate::SorterHelper
- Inherits:
-
Object
- Object
- WillSortate::SorterHelper
- Defined in:
- lib/will_sortate/helpers/sorter_helper.rb
Instance Method Summary collapse
-
#initialize(args) ⇒ SorterHelper
constructor
A new instance of SorterHelper.
- #next_sort_order ⇒ Object
- #params ⇒ Object
Constructor Details
#initialize(args) ⇒ SorterHelper
Returns a new instance of SorterHelper.
3 4 5 6 7 8 |
# File 'lib/will_sortate/helpers/sorter_helper.rb', line 3 def initialize args @collection = args[:collection] @sort_field = args[:sort_field] @default_sort_order = args[:default_sort_order] || 'asc' @params = args[:params] end |
Instance Method Details
#next_sort_order ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/will_sortate/helpers/sorter_helper.rb', line 10 def next_sort_order if @collection.sortated_field == @sort_field.to_s @collection.sortated_order == 'asc' && 'desc' || 'asc' else @default_sort_order end end |
#params ⇒ Object
18 19 20 |
# File 'lib/will_sortate/helpers/sorter_helper.rb', line 18 def params @params.merge sort: "#{@sort_field}_#{next_sort_order}" end |