[Rails] # of entrys in different months

Adam Denenberg straightflush at gmail.com
Tue Jan 10 17:24:36 GMT 2006


find_by_sql("select count(*) as total from  from posts where category
= 1 group by year,month)


On 1/10/06, Jens-Christian Fischer <jcf at invisible.ch> wrote:
>
> Am 10.01.2006 um 17:11 schrieb Melange:
>
> > right now im writing a weblog as my first project in rails. Most tings
> > seems to be working great :), but there is (a least) one thing left i
> > can't figure out how to do.
> > As most weblogs i would like to have an archive, whick looks like
> > this:
> >
> > January 2006 (42)
> >
> > where (x) is the number of posts that month.
> >
> > How do i do this "the rails way"? the date in my table has the type
> > "datetime"
>
>
> The rails way would probably be something like:
>
> class Post
>     def self.number_of_posts(year, month)
>       Post.count "month(postdate) = month and year(postdate) = year"
>     end
> end
>
> Note: Dependent on the DBMS you use.
>
> then you can call
>
> Post.number_of_posts(2006, 1)
>
> cu jc
>
> --
> InVisible GmbH, Langgrütstrasse 172, 8047 Zürich
> Phone: +41 44 401 09 30
> http://www.invisible.ch   http://not.invisible.ch
>
>
>
> _______________________________________________
> Rails mailing list
> Rails at lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>
>


More information about the Rails mailing list