[Rails] # of entrys in different months
Jens-Christian Fischer
jcf at invisible.ch
Tue Jan 10 17:08:54 GMT 2006
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2361 bytes
Desc: not available
Url : http://wrath.rubyonrails.org/pipermail/rails/attachments/20060110/7ccf57fc/smime-0001.bin
More information about the Rails
mailing list