1

How do I do it? It's sort of like currently trending posts i.e. the posts don't necessarily have to be created in the last 2 hours.

scope :top, ->{ order(:cached_votes_total => :desc) }
scope :trending, ?
Arif
  • 712
  • 11
  • 20
  • How about `scope :trending, -> { where(created_at: 2.hours.from_now) }` – Arup Rakshit Jul 15 '16 at 17:27
  • @ArupRakshit That would show the posts created in the last 2 hours correct? That's not what I'm looking for – Arif Jul 15 '16 at 17:42
  • You are right. Then what you are looking for? I read the subject then wrong, and I don't know what you want :) – Arup Rakshit Jul 15 '16 at 17:53
  • @ArupRakshit I'm looking for the _most liked posts_ in past 2 hours. So basically like `order(:cached_votes_total => :desc)` (this lists the most liked posts _of all time_ in desc order), except the `created_at` for likes is limited to `2.hours.from_now`. I hope I made myself clear – Arif Jul 15 '16 at 18:03
  • i think you should fire ActsAsVotable::Vote.where(vote_flag: "t") where you get all the liked votes within created_at 2 hours ago.. or else. than you should use order(:cached_votes_total => :desc) method for highest voted post – Vishal Jul 15 '16 at 19:04
  • @Vishal Could you please explain in details? Running `ActsAsVotable::Vote.where(vote_flag: "t")` in the console does show all the votes, but I dunno how to connect those votes to the posts. I can iterate through `Post.all` and find the votes that have been made in the last 2 hours using `post.votes_for.where('created_at >= ?', 2.hours.ago)` but that's about the progress I've made. – Arif Jul 16 '16 at 08:05

0 Answers0