How to use sort_link with model instance method in rails 4 with Ransack Gem? How to use sort_link with model instance method in rails 4 with Ransack Gem? sqlite sqlite

How to use sort_link with model instance method in rails 4 with Ransack Gem?


Ransack is very smart itself, try to change line

<th><%= sort_link(@q,:role_users_user_count) %></th>

to

<th><%= sort_link(@q, :users_count) %></th>

Explanation: In the variable @q you keep a Ransack query object on the model Role, if you call sort_link on @q it will apply users_count as "join users relation and order by users count".