Forum: Ruby on Rails Order By Number of Comments

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Hamza (Guest)
on 2006-04-03 18:36

I am new to Ruby on Rails, so I apologise if this has been answered
elsewhere.  I have had a look through the list but I can't seem to find
what I am trying to do.

I have implemented the standard blog and comments app from the
screencast.  However I am trying to extend the functionality.

I want to be able to display a list of posts and order them by the total
number of comments they have.  It will act as a most discussed view.

This is what I have been trying in the controller, with no luck :

def show_discussed
  @contents.find(:all, :order => "contents.comment.size DESC", :joins =>

I have got some SQL that works : (I renamed posts to contents)

select contents.*, count(*) as comment_total from contents, comments
WHERE = comments.content_id group by;

But this does not return the posts with no comments.

I would really appreciate any help.

Thank you in advance.

This topic is locked and can not be replied to.