17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/gridy/view_helpers.rb', line 17
def (field, title = nil, sortable: false)
unless sortable
return title || field.to_s.titleize
end
uri = URI(request.url)
params = Rack::Utils.parse_query(uri.query)
if params["sort"].to_s.start_with?(field.to_s)
icon = params["sort"].to_s.end_with?("asc") ? "▲" : "▼"
else
icon = ""
end
params["sort"] = "#{field} #{params["sort"] == "#{field} asc" ? "desc" : "asc"}"
uri.query = params.to_query
link_to(uri.to_s, class: "") do
content_tag(:span, "#{title || field.to_s.titleize} #{icon}".html_safe)
end
end
|