saucy/app/helpers/members_helper.rb

25 lines
543 B
Ruby
Raw Normal View History

2022-06-25 12:48:46 +00:00
module MembersHelper
def link_to_current_with_sort text, default_sort
current_sort = stringify(sort_params)
pp [default_sort, current_sort]
if default_sort == current_sort
link_to text, members_path(sort: invert_sort_order(current_sort))
else
link_to text, members_path(sort: default_sort)
end
end
private
def stringify(sort)
"#{sort.keys.first.to_s}.#{sort.values.first.to_s}"
end
def invert_sort_order(sort)
sort.sub(/\.(asc|desc)$/) { |x| x == '.asc' ? '.desc' : '.asc' }
end
end