On 3/23/2010 2:56 PM, DanC wrote:
I have built a simple forum but am having difficult getting the topics
to display in the order of their latest reply.

The associations are as follows:

class Forum<  ActiveRecord::Base
   has_many :topics, :order =>  "sticky DESC, created_at DESC"
   has_many :replies, :through =>  :topics

class Topic<  ActiveRecord::Base
   belongs_to :forum
   has_many :replies, :order =>  "created_at", :dependent =>  :destroy

class Reply<  ActiveRecord::Base
    belongs_to :topic

And in my controller I am calling     @topics = @forum.topics

What I would like to do is sort the topics by the created_at of their
most recent posts.

Any advice appreciated.
Add a last_reply_at field to Topic. Add a after_save to Reply that updates last_reply_at. When you find all topics sort by last_reply_at.
Thanks,

Dan



--
Jack Christensen
ja...@hylesanderson.edu

--
You received this message because you are subscribed to the Google Groups "Ruby on 
Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to