Working on showing and hiding comments and by default I show the 2 most recent:
Helper method:
def comments(micropost_id)
Comment.where(:micropost_id => micropost_id).limit(2).order("created_at DESC").reverse
end
2 comments will be show in this way:
Comment 1 (sent 10 hours ago)
Comment 2 (sent an hour ago)
I have a show all comments clickable button which adds all the comments for that particular micropost to the list. This is fine apart from the fact that I need all comments except the 2 most recent.
Using offset(2) takes away the first 2 comments. I basically need to do the opposite of this. So wondering if there is something I can chain onto the offset method to achieve this or if there is a dedicated method to doing the opposite of what .offset() does?
Thanks in advance
Kind regards
You can do as sergio suggests, chop off the last two after you load them from the database or you can reverse the order clause in the query, offset by two and then reverse the result.