Module: SortOut::Helpers
- Defined in:
- lib/sort_out/helpers.rb
Instance Method Summary collapse
- #sortable(column, title = nil, options = {}) ⇒ Object
- #sortable_current(columns, default, options) ⇒ Object
- #sortable_fields ⇒ Object
Instance Method Details
#sortable(column, title = nil, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/sort_out/helpers.rb', line 4 def sortable(column, title = nil, = {}) .reverse_merge! default: false, direction: true, params: {} title ||= column.titleize direction = nil if column.to_s == SortOut.sort || ([:default] and SortOut.sort.blank?) if SortOut.direction.blank? if [:default].to_s == 'desc' and SortOut.sort.blank? title << '▲' if [:direction] else direction = "desc" title << '▼' if [:direction] end else title << '▲' if [:direction] end end #▴ ▾ ▼ ▲ link_to title, params.merge({ sort: column, direction: direction }.merge([:params])) end |
#sortable_current(columns, default, options) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/sort_out/helpers.rb', line 31 def sortable_current(columns, default, ) .reverse_merge! model_name: controller_name.singularize column = if SortOut.sort.present? and columns.include? SortOut.sort.to_sym SortOut.sort.to_sym else default.first end title = tl("#{[:model_name]}.#{column.to_s}") if SortOut.direction.blank? if default[1].to_s == 'desc' and SortOut.sort.blank? title << '▲' else title << '▼' end else title << '▲' end end |