# Finding via recently created nested resource

**URL:** <https://www.ruby-forum.com/t/finding-via-recently-created-nested-resource/145454>\
**Category:** Rails\
**Created:** [August 9, 2008, 10:07pm UTC](https://www.ruby-forum.com/t/finding-via-recently-created-nested-resource/145454 "2008-08-09T22:07:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kylemathews](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/51bf81/32.png) [@kylemathews](https://www.ruby-forum.com/u/kylemathews)\
**Post date:** [August 9, 2008, 10:07pm UTC](https://www.ruby-forum.com/t/finding-via-recently-created-nested-resource/145454/1 "2008-08-09T22:07:52Z")

</div>

I have Articles and Comments. Comments are RESTfully nested in Articles  
(articles/1/comments/2 etc).

I am attempting to display articles via how recently created their last  
comment was – basically how any forum is ordered. How would I do this?  
Thank you very much.

---

<div class="post-metadata">

**Author:** ![kylemathews](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/51bf81/32.png) [@kylemathews](https://www.ruby-forum.com/u/kylemathews)\
**Post date:** [August 11, 2008, 9:20am UTC](https://www.ruby-forum.com/t/finding-via-recently-created-nested-resource/145454/2 "2008-08-11T09:20:04Z")

</div>

On Sat, Aug 9, 2008 at 10:07 PM, Kyle M. \<  
removed\_email\_address@domain.invalid\> wrote:

I am attempting to display articles via how recently created their last

> comment was – basically how any forum is ordered. How would I do this?  
> Thank you very much.

One possible approach is to:

1. add a commented\_at timestamp column to Article.

2. in your Comment model, put in code for after\_create to set the  
parent  
Article’s commented\_at column to the current date time.

3. now, when you do Article.find, just add an option for :order =\>  
‘commented\_at DESC’

Hope this helps.

Franz
