Hey all, I''m doing something like that: #in my controller: @posts=Post.find(:all,:group=>''created_on'') #then in my view: <% for post in @posts %> <div id=posts><% ''Posts created on ''+post.created_on%> @currentposts=Post.find_by_created_on(post.created_on) <% for p in @currentposts %> <li>p.title</li> <% end %> </div> <% end %> Any idea how I could get the list of posts that were created on each date without having to do that Post.find query in my view? thanx in advance Pat --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Patrick :> Any idea how I could get the list of posts that were created > on each date without having to do that Post.find query in my view?You can use Enumerable#group_by. sth like : Post.find(:all).group_by(&:created_on) -- Jean-François. -- À la renverse. --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 12/4/06, Jean-François <jf.web3-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Patrick : > > Any idea how I could get the list of posts that were created > > on each date without having to do that Post.find query in my view? > > You can use Enumerable#group_by. > sth like : Post.find(:all).group_by(&:created_on) >ok thanx a lot, and what if I want to group them by day cause I''m using datetime which also have hours and second. I would like to group them by day only. Any idea? thanx in advance Pat --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> On 12/4/06, Jean-Franois <jf.web3-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Patrick : >>> Any idea how I could get the list of posts that were created >>> on each date without having to do that Post.find query in my view? >> >> You can use Enumerable#group_by. >> sth like : Post.find(:all).group_by(&:created_on) >> > ok thanx a lot, and what if I want to group them by day cause I''m > using datetime which also have hours and second. I would like to group > them by day only. Any idea? > thanx in advanceYou could always do... @posts = Post.find(:all, :order => ''created_on'') Then in your view.. <% last_day = 0 %> <% @posts.each do |p| %> <% if p.created_on.day != last_day %> ... print out a date header or something... <% last_day = p.created_on.day %> <% end %> .... print out p.... <% end %> This will break if you have consecutive rows in differing months/years but have the same day, but to get around that change the last_day to laste_date and set it appropriately and you should be fine. -philip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You might find Chronic plugin useful, check it out : http://chronic.rubyforge.org/> Any idea how I could get the list of posts that were created on each > date without having to do that Post.find query in my view? > > thanx in advance > > Pat >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Patrick Aljord wrote:> On 12/4/06, Jean-Fran�ois <jf.web3-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Patrick : >> > Any idea how I could get the list of posts that were created >> > on each date without having to do that Post.find query in my view? >> >> You can use Enumerable#group_by. >> sth like : Post.find(:all).group_by(&:created_on) >> > ok thanx a lot, and what if I want to group them by day cause I''m > using datetime which also have hours and second. I would like to group > them by day only. Any idea? > > thanx in advance > > PatPost.find(:all).group_by { |post| post.created_on.strftime(''%Y-%m-%d) } -- 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 -~----------~----~----~----~------~----~------~--~---
On 12/5/06, Alex Wayne <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:>> Post.find(:all).group_by { |post| post.created_on.strftime(''%Y-%m-%d) } >thanx lot. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---