After reading this (the @thomasfedb answer), I though this would work:
@categories = Category.joins(:category_users).where("category_users.user_id = ? AND category_users.interested_learning IS TRUE", current_user.id)
@search = Resource.joins(:categories).where(category_id: @categories.subtree_ids).search_filter(params[:search_filter]).paginate(:per_page => 20, :page => params[:page]).search(params[:q])
But instead, I receive this error
undefined method `subtree_ids' for #<ActiveRecord::Relation:0x007fce832b1070>
I also tried @Rahul answer from here
Without the Ancestry descendants, it is working like this
@search = Resource.joins(:category_users).where("category_users.user_id = ? AND category_users.interested_learning IS TRUE", current_user.id).search_filter(params[:search_filter]).paginate(:per_page => 20, :page => params[:page]).search(params[:q])
Although I want to do the Ransack search after finding the descendants, the error also appears without Ransack. For this reason, I haven't included it in the title. Without Ransack, it would be like this:
@categories = Category.joins(:category_users).where("category_users.user_id = ? AND category_users.interested_learning IS TRUE", current_user.id)
@resources = Resource.joins(:categories).where(category_id: @categories.subtree_ids)
I would appreciate any advices on this could work