Search code examples
ruby-on-railsactiverecordransack

Searching the fields 2 level above of associations using Ransack


class UserGroup
 has_many :users
end
class User
 has_many :posts
end
class Post
end

Can we search the fields in user_group in the position of post using ransack?

Thanks!


Solution

  • you may try something like Post.ransack(user_user_group_type_eq: 'admin')

    here I am assuming UserGroup class will have a column type and comparing it to value admin