Module: Sortable::SortableHelper
- Defined in:
- app/helpers/sortable/sortable_helper.rb
Instance Method Summary collapse
- #sortable(column, default: false, direction: :asc, scope: nil, **options, &block) ⇒ Object
- #sortable_label_for(label, active, direction, scope) ⇒ Object
Instance Method Details
#sortable(column, default: false, direction: :asc, scope: nil, **options, &block) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/helpers/sortable/sortable_helper.rb', line 4 def sortable(column, default: false, direction: :asc, scope: nil, **, &block) current = column.to_s == params[:sort] || params[:sort].blank? && default current_direction = (params[:direction] || direction).to_s new_direction = direction.to_s if current new_direction = current_direction.to_s == "asc" ? "desc" : "asc" end url = url_for params.permit!.merge(sort: column, direction: new_direction) link_to(url, ) do label = block_given? ? capture(&block) : column sortable_label_for(label, current, current_direction, scope) end end |
#sortable_label_for(label, active, direction, scope) ⇒ Object
21 22 23 |
# File 'app/helpers/sortable/sortable_helper.rb', line 21 def sortable_label_for(label, active, direction, scope) render "sortable/label", label: label, active: active, direction: direction, scope: scope end |