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) December 2005 (60) November 2005 (2) October 2005 (101) September 2005 (4) August 2005 (2) July 2005 (101010) 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" thanks in advence. -- Posted via http://www.ruby-forum.com/.
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
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@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@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > >
jonathan Mcintire
2006-Jan-10 17:32 UTC
[Rails] SearchGenerator Question - Partial view template.
Has anyone here used the SearchGenerator? I''m having trouble setting up the "Partial" view, the documentation makes me think a Partial template is included, but I don''t see one. I have the search index and generic view file. Anyone have the code that is in partial view? Or how to set it up? Thanks __________________________________________ Yahoo! DSL ? Something to write home about. Just $16.99/mo. or less. dsl.yahoo.com
Adam Denenberg wrote:> find_by_sql("select count(*) as total from from posts where category > = 1 group by year,month)I''m not an SQL expert, but how does that help when his date is a datetime? -- Posted via http://www.ruby-forum.com/.
Lance Ball
2006-Jan-10 17:47 UTC
[Rails] SearchGenerator Question - Partial view template.
On 1/10/06, jonathan Mcintire <hatejonny@yahoo.com> wrote:> Has anyone here used the SearchGenerator? I''m having > trouble setting up the "Partial" view, the > documentation makes me think a Partial template is > included, but I don''t see one. I have the search index > and generic view file. > > Anyone have the code that is in partial view? Or how > to set it up?Hi Jonathan I haven''t used SearchGenerator, so I''m not really one to answer your question. Instead, I''ll shill for my own Indexed Search Engine (http://langwell-ball.com/indexed-search). I chose not to use Search Generator for my purposes primarily because it integrated SimpleSearch - which I think is too simple. It doesn''t stem words, and it does a full text search on your database, which is definitely going to be slow if your data is of any size. This doesn''t really answer your question, I know. Sorry about that. ;-) But if you do feel like giving Indexed Search Engine a try, please let me know how it goes. Any and all feedback is welcome. Lance Ball
jonathan Mcintire
2006-Jan-10 18:04 UTC
[Rails] SearchGenerator Question - Partial view template.
Is the engine available on Textdrive? If I use this search and then migrate to Textdrive would I have any issues? --- Lance Ball <lanceball@gmail.com> wrote:> On 1/10/06, jonathan Mcintire <hatejonny@yahoo.com> > wrote: > > Has anyone here used the SearchGenerator? I''m > having > > trouble setting up the "Partial" view, the > > documentation makes me think a Partial template is > > included, but I don''t see one. I have the search > index > > and generic view file. > > > > Anyone have the code that is in partial view? Or > how > > to set it up? > > Hi Jonathan > > I haven''t used SearchGenerator, so I''m not really > one to answer your > question. Instead, I''ll shill for my own Indexed > Search Engine > (http://langwell-ball.com/indexed-search). I chose > not to use Search > Generator for my purposes primarily because it > integrated SimpleSearch > - which I think is too simple. It doesn''t stem > words, and it does a > full text search on your database, which is > definitely going to be > slow if your data is of any size. > > This doesn''t really answer your question, I know. > Sorry about that. > ;-) But if you do feel like giving Indexed Search > Engine a try, > please let me know how it goes. Any and all > feedback is welcome. > > Lance Ball > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >__________________________________________ Yahoo! DSL ? Something to write home about. Just $16.99/mo. or less. dsl.yahoo.com
sorry missed that. adam On 1/10/06, Kasper Kilikus <foo@dodgeit.com> wrote:> Adam Denenberg wrote: > > find_by_sql("select count(*) as total from from posts where category > > = 1 group by year,month) > > I''m not an SQL expert, but how does that help when his date is a > datetime? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On Tue, Jan 10, 2006 at 06:40:34PM +0100, Kasper Kilikus wrote: } Adam Denenberg wrote: } > find_by_sql("select count(*) as total from from posts where category } > = 1 group by year,month) } } I''m not an SQL expert, but how does that help when his date is a } datetime? It doesn''t. The following may be PostgreSQL-specific. Not sure. SELECT *, COUNT(*) FROM ( SELECT extract(year FROM posted_date) AS year, extract(month FROM posted_date) AS month FROM posts ) GROUP BY year, month --Greg
Lance Ball
2006-Jan-10 19:26 UTC
[Rails] SearchGenerator Question - Partial view template.
On 1/10/06, jonathan Mcintire <hatejonny@yahoo.com> wrote:> Is the engine available on Textdrive? If I use this > search and then migrate to Textdrive would I have any > issues?It''s just a plain ole Rails engine (http://rails-engines.org/) with no dependencies on anything outside of rails. I haven''t personally tested it on Textdrive, but since they''re one of the defacto RoR hosting providers it shouldn''t be a problem. Lance
jonathan Mcintire
2006-Jan-10 19:44 UTC
[Rails] SearchGenerator Question - Partial view template.
Yeah, I just wasn''t sure if they had the "engines" working on their site. Thanks for the response though, I think I will try your search, actually. I''ll let you know how it turns out(I''m sure I''ll have some problem). Thanks for the help. Jonathan --- Lance Ball <lanceball@gmail.com> wrote:> On 1/10/06, jonathan Mcintire <hatejonny@yahoo.com> > wrote: > > Is the engine available on Textdrive? If I use > this > > search and then migrate to Textdrive would I have > any > > issues? > > It''s just a plain ole Rails engine > (http://rails-engines.org/) with no > dependencies on anything outside of rails. I > haven''t personally > tested it on Textdrive, but since they''re one of the > defacto RoR > hosting providers it shouldn''t be a problem. > > Lance > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >__________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
mysql version (that i originally meant): mysql> select count(*) as total, date_format(created_on,''%b'') as month , date_format(created_on,''%Y'') as year from posts group by month,year ; +-------+-------+------+ | total | month | year | +-------+-------+------+ | 1 | NULL | 0000 | | 8 | Dec | 2005 | | 8 | Jan | 2006 | | 11 | Nov | 2005 | | 19 | Oct | 2005 | +-------+-------+------+ 5 rows in set (0.00 sec) -adam On 1/10/06, Gregory Seidman <gsslist+ror@anthropohedron.net> wrote:> On Tue, Jan 10, 2006 at 06:40:34PM +0100, Kasper Kilikus wrote: > } Adam Denenberg wrote: > } > find_by_sql("select count(*) as total from from posts where category > } > = 1 group by year,month) > } > } I''m not an SQL expert, but how does that help when his date is a > } datetime? > > It doesn''t. The following may be PostgreSQL-specific. Not sure. > > SELECT *, COUNT(*) > FROM ( > SELECT extract(year FROM posted_date) AS year, > extract(month FROM posted_date) AS month > FROM posts > ) > GROUP BY year, month > > --Greg > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
James Adam
2006-Jan-10 23:06 UTC
[Rails] SearchGenerator Question - Partial view template.
''engines'' aren''t things that your host needs to support - they are just plugins, like any other rails plugin or bit of code, that you can use in your application anywhere. - james On 1/10/06, jonathan Mcintire <hatejonny@yahoo.com> wrote:> Yeah, I just wasn''t sure if they had the "engines" > working on their site. > Thanks for the response though, I think I will try > your search, actually. I''ll let you know how it turns > out(I''m sure I''ll have some problem). Thanks for the > help. > > Jonathan > > --- Lance Ball <lanceball@gmail.com> wrote: > > > On 1/10/06, jonathan Mcintire <hatejonny@yahoo.com> > > wrote: > > > Is the engine available on Textdrive? If I use > > this > > > search and then migrate to Textdrive would I have > > any > > > issues? > > > > It''s just a plain ole Rails engine > > (http://rails-engines.org/) with no > > dependencies on anything outside of rails. I > > haven''t personally > > tested it on Textdrive, but since they''re one of the > > defacto RoR > > hosting providers it shouldn''t be a problem. > > > > Lance > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Lance Ball
2006-Jan-10 23:09 UTC
[Rails] SearchGenerator Question - Partial view template.
On 1/10/06, James Adam <james.adam@gmail.com> wrote:> ''engines'' aren''t things that your host needs to support - they are > just plugins, like any other rails plugin or bit of code, that you can > use in your application anywhere.True - though I suppose if your hosting provider has an older version of rails (pre 0.13.x or whenever engines were introduced) it would be an issue.