Module: Sortiri::ViewHelpers::TableSorter

Defined in:
lib/sortiri/view_helpers/table_sorter.rb

Instance Method Summary collapse

Instance Method Details



6
7
8
9
10
11
12
13
14
# File 'lib/sortiri/view_helpers/table_sorter.rb', line 6

def sort_link(activerecord_relation_object, column, title, css_class = nil)
  sort_string = params[:sort].presence || activerecord_relation_object.klass.default_sort
  sorter = Sortiri::Utils.new(sort_string: sort_string, column_name: column)

  link_to(request.query_parameters.merge({ sort: "#{sorter.direction}#{column}" }), class: css_class) do
    concat title
    concat (:i, '', class: sorter.icon_class)
  end
end