[Rails] Re: counting blog comments

2009-09-18 Thread Gourav
I think, you must have Post-'has many-Comments relationship So, to find number of comments: post.comments.count will give you total number of comments of a post. -Gourav On Sep 18, 10:58 am, Mark polluxop...@gmail.com wrote: I have posts  and comments, and I'd like to display the number of

[Rails] Re: counting blog comments

2009-09-18 Thread Mark
That did it. I think I've been staring at the monitor too long... :-) On Sep 18, 2:34 am, Gourav gouravtiwar...@gmail.com wrote: I think, you must have Post-'has many-Comments relationship So, to find number of comments: post.comments.count will give you total number of comments of a post.

[Rails] Re: counting blog comments

2009-09-18 Thread E. Litwin
Depending on performance needs, you can also look at the counter_cache option for the ActiveRecord association. Your current approach has to query the child table to get the count, which could be a performance hit on a big site. Don't prematurely optimize though - it's just good to know about