# Grab only the latest comment

**URL:** <https://www.ruby-forum.com/t/grab-only-the-latest-comment/174466>\
**Category:** Rails\
**Created:** [August 27, 2009, 3:40am UTC](https://www.ruby-forum.com/t/grab-only-the-latest-comment/174466 "2009-08-27T03:40:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gkrdvl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e47c2d/32.png) [@gkrdvl](https://www.ruby-forum.com/u/gkrdvl)\
**Post date:** [August 27, 2009, 3:40am UTC](https://www.ruby-forum.com/t/grab-only-the-latest-comment/174466/1 "2009-08-27T03:40:35Z")

</div>

Hi all

In a typical User - Post - Comment model in Rails, every user can  
create a Post and also can create Comment, question is how to grab  
every user latest comment on specific post.

Example:

Post A have 3 user making comment  
User 1 have 5 comment  
User 2 have 6 comment  
User 3 have 2 comment

So the view I want is just the latest comment for every user:

Post A have 3 user making  
User 1 latest comment  
User 2 latest comment  
user 3 latest comment

How to do it ?

thanks

---

<div class="post-metadata">

**Author:** ![gkrdvl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e47c2d/32.png) [@gkrdvl](https://www.ruby-forum.com/u/gkrdvl)\
**Post date:** [August 27, 2009, 6:47am UTC](https://www.ruby-forum.com/t/grab-only-the-latest-comment/174466/2 "2009-08-27T06:47:51Z")

</div>

> **[ActiveRecord::Base](https://api.rubyonrails.org/classes/ActiveRecord/Base.html)**
>
> Active Record Active Record objects don't specify their attributes directly, but rather infer them from the table definition with which they're linked.
