I have a rails app with view code long in need of an overhaul. Some of the first app code I wrote was designed to display entires belonging to a given date, under a date header derived from a model timestamp field. For each day, I list the corresponding entries for that day under the date as a header. Here''s an example: 07/09/1976 --- Entry 1 --- Entry 2 --- Entry 3 07/08/1976 --- Entry 1 --- Entry 2 The results are in a @diary object which I loop through. I''d be happy to post my code, which is ugly, though i wanted to find out if there was a helper to do this, or if there''s a technique that people use to easily: 1. extract the date from a timestamp, and write it as a header 2. list all the corresponding entries for that day underneath it ...etc. etc. Any techniques out there to use? ...or are there any helpers I might not know about to make this work? Thanks for your help in advance. -A --~--~---------~--~----~------------~-------~--~----~ 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 Jun 30, 2008, at 11:55 AM, ressister wrote:> > I have a rails app with view code long in need of an overhaul. Some > of the first app code I wrote was designed to display entires > belonging to a given date, under a date header derived from a model > timestamp field. For each day, I list the corresponding entries for > that day under the date as a header. Here''s an example: > > 07/09/1976 > --- Entry 1 > --- Entry 2 > --- Entry 3 > > 07/08/1976 > --- Entry 1 > --- Entry 2 > > The results are in a @diary object which I loop through. I''d be happy > to post my code, which is ugly, though i wanted to find out if there > was a helper to do this, or if there''s a technique that people use to > easily: > > 1. extract the date from a timestamp, and write it as a header > 2. list all the corresponding entries for that day underneath it > > ...etc. etc. > > Any techniques out there to use? ...or are there any helpers I might > not know about to make this work?Google for "group_by". Here''s some examples. http://weblog.rubyonrails.org/2006/3/1/new-in-rails-enumerable-group_by-and-array-in_groups_of http://justbarebones.blogspot.com/2007/10/ruby-groupby.html --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Awesome Phillip, this is very helpful, thanks. -A On Jun 30, 3:31 pm, Philip Hallstrom <phi...-LSG90OXdqQE@public.gmane.org> wrote:> On Jun 30, 2008, at 11:55 AM, ressister wrote: > > > > > > > I have a rails app with view code long in need of an overhaul. Some > > of the first app code I wrote was designed to display entires > > belonging to a given date, under a date header derived from a model > > timestamp field. For each day, I list the corresponding entries for > > that day under the date as a header. Here''s an example: > > > 07/09/1976 > > --- Entry 1 > > --- Entry 2 > > --- Entry 3 > > > 07/08/1976 > > --- Entry 1 > > --- Entry 2 > > > The results are in a @diary object which I loop through. I''d be happy > > to post my code, which is ugly, though i wanted to find out if there > > was a helper to do this, or if there''s a technique that people use to > > easily: > > > 1. extract the date from a timestamp, and write it as a header > > 2. list all the corresponding entries for that day underneath it > > > ...etc. etc. > > > Any techniques out there to use? ...or are there any helpers I might > > not know about to make this work? > > Google for "group_by". Here''s some examples. > > http://weblog.rubyonrails.org/2006/3/1/new-in-rails-enumerable-group_...http://justbarebones.blogspot.com/2007/10/ruby-groupby.html--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---