How to show only latest tweet of user in Tweet Index action
I have User has_many tweets. In my tweets index action I want to show only
the latest tweet by each user.
In my controller I have:
@tweets = Tweet.includes(:user, :likes).order('tweets.created_at DESC')
If I iterate through @tweets, I can see all the tweets in Descending
order. If USer has 5 tweets I can see all 5. I just want to be able to to
see the latest tweet of each user. How can I do this without N+1 issue?
No comments:
Post a Comment