rubyonrailsin

A Ruby and Rails talk

Tuesday, March 23, 2010


[Rails] Sorting forum topics by the most recent replies

by rubyonrailsin 0 comments

Tag


Share this post:
Design Float
StumbleUpon
Reddit

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.

Thanks,

Dan

--
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-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment

Subscribe feeds via e-mail

Blog Archive