Here I want to sort product list as per current user. The user clicked the product most comes first in list and sort accordingly.
Here I have table product_counts
which store user_id
product_id
and counts
.
I tried this, but it taking a lot of queries to run which isn't good.
Product.all.sort_by{ |r| r.product_clicks.where(user_id: user.id).first.try(:count).to_i }.reverse!