Hello, I want to do archive list like in any blogs? But I cannot really think how it''s done? Do they group the created_at and then extract the column, but this would work since created_at have different dates all the long way down? I hope someone can help :) Thanks Regards, Jamal -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
It might vary between databases, but in MySQL you could do something
like:
:select => "DATE_FORMAT(''%m/%Y'') as
month_year,COUNT(posts.id) as
count"
:group => "month_year"
:order => "month_year"
That''s just off the top of my head, but the idea is to use a GROUP BY
clause on month.
On May 23, 12:34 pm, Jamal Soueidan
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> Hello,
>
> I want to do archive list like in any blogs? But I cannot really think
> how it''s done?
>
> Do they group the created_at and then extract the column, but this would
> work since created_at have different dates all the long way down?
>
> I hope someone can help :)
>
> Thanks
> Regards,
> Jamal
>
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
dasil003 wrote:> It might vary between databases, but in MySQL you could do something > like: > > :select => "DATE_FORMAT(''%m/%Y'') as month_year,COUNT(posts.id) as > count" > :group => "month_year" > :order => "month_year" > > That''s just off the top of my head, but the idea is to use a GROUP BY > clause on month. > > On May 23, 12:34 pm, Jamal Soueidan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>I''m using MySQL database, and I cannot really get your example to work... I have column called "created_at" def archive @archive = Post.find(:all, :select => "DATE_FORMAT(''%m %Y'') as month_year, COUNT(posts.id) as count", :group => "month_year", :order => "month_year") end and I''m getting error as follow: Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '') as month_year, COUNT(posts.id) as count FROM posts GROUP BY month_year ORDER'' at line 1: SELECT DATE_FORMAT(''%m %Y'') as month_year, COUNT(posts.id) as count FROM posts GROUP BY month_year ORDER BY month_year -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I think I got it right now :) I forgot to add the column name to date_format as below date_format(date_column, ''%M %D, %Y'') -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---