2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'app/helpers/bmc/sorting_helper.rb', line 2
def sortable_column(name, column, options = {})
unless column.is_a?(Symbol)
raise ArgumentError, "invalid column, please use symbol"
end
current_column, current_direction = sortable_column_order
if current_column == column
if current_direction == :asc
name = "#{name} ↓"
new_sort_param = "-#{column}"
end
if current_direction == :desc
name = "#{name} ↑"
new_sort_param = column
end
klass = "sort #{current_direction}"
else
new_sort_param = column
klass = "sort"
end
unless (url_params = options.delete(:url_params))
url_params = (params.try(:permit!) || params).to_h.symbolize_keys
end
url_params[:sort] = new_sort_param
html_options = {class: klass}.merge(options)
link_to(name, url_params, html_options)
end
|