first time poster. I am trying to sort a table of users using the Ransack gem and Kaminari for pagination. When I use name, id, etc. sorting works but when I try an associat
I found a solution:
Controller:
def index
sql = "users.*, (select count(posts.id) from posts\
where posts.user_id = users.id) as count"
@search = User.select(sql).search(params[:q])
if params[:q] && params[:q][:s].include?('count')
@users = @search.result.order(params[:q][:s])
else
@users = @search.result
end
.......
end
View:
<%= sort_link @search, :count, "posts count" %>