I have this inside User model
def self.home_opinions (user)
home_opinions = user.opinions
user.follows.find_each do |follow|
home_opinions+=(follow.opinions)
end
home_opinions.order_by_most_recent
end
I have this scope inside Opinion model
scope :order_by_most_recent, -> { includes(:author).order(created_at: :desc) }
It shows this error
undefined method `order_by_most_recent' for #<Array:0x00007eff64d076f8>
But when I try User.home_opinions(User.find(9)) inside rails console
It works
I have two questions
- why It shows the error
- What are the best practices for this code maybe using
includes?