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
You can add a scope to your User model:
User
def self.with_posts joins(:posts).group('posts.id').select('users.*, count(posts.id) as posts_count') end
and use it like this:
@search = User.with_posts.search(params[:q]) # Ransack
then, you can treat posts_count like any other attribute.
posts_count