Module: Mincer::ActionView::SortHelper
- Defined in:
- lib/mincer/action_view/sort_helper.rb
Instance Method Summary collapse
- #opposite_order_for(collection, attribute) ⇒ Object
-
#sort_class_for(collection, attribute) ⇒ Object
Returns chevron class, if attribute is the one that was used for sorting.
-
#sort_url_for(collection, attribute, permitted_params = params) ⇒ Object
Returns sorting URL for collection and attribute.
Instance Method Details
#opposite_order_for(collection, attribute) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/mincer/action_view/sort_helper.rb', line 12 def opposite_order_for(collection, attribute) return nil unless collection.sort_attribute == attribute.to_s if collection.sort_order.to_s.downcase == 'asc' 'desc' elsif collection.sort_order.to_s.downcase == 'desc' 'asc' else 'asc' end end |
#sort_class_for(collection, attribute) ⇒ Object
Returns chevron class, if attribute is the one that was used for sorting
collection
- instance of QueryObject attribute
- Attribute that will be used to sort table
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mincer/action_view/sort_helper.rb', line 28 def sort_class_for(collection, attribute) return nil unless collection.sort_attribute == attribute.to_s if collection.sort_order.downcase == 'asc' ::Mincer.config.sorting.asc_class elsif collection.sort_order.downcase == 'desc' ::Mincer.config.sorting.desc_class else '' end end |
#sort_url_for(collection, attribute, permitted_params = params) ⇒ Object
Returns sorting URL for collection and attribute
collection
- instance of QueryObject attribute
- Attribute that will be used to sort table
8 9 10 |
# File 'lib/mincer/action_view/sort_helper.rb', line 8 def sort_url_for(collection, attribute, permitted_params = params) url_for(permitted_params.merge(:sort => attribute, :order => opposite_order_for(collection, attribute))) end |