Finding via recently created nested resource

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.

On Sat, Aug 9, 2008 at 10:07 PM, Kyle M. <
[email protected]> 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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs