Does anyone know the best way to display a list of rows grouped by month in a view? An example would be: December Dec. 15, Saturday at 8:30pm: Some Field Dec. 9, Sunday at 8:30pm: Some Field Dec. 5, Wednesday at 8:30pm: Some Field November Nov. 15, Saturday at 8:30pm: Some Field Thanks for any help. -- 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 -~----------~----~----~----~------~----~------~--~---
yup. Ryancasts to the rescue - http://railscasts.com/episodes/29 On Dec 12, 4:52 pm, Philip Hallstrom <ra...-SUcgGwS4C16SUMMaM/qcSw@public.gmane.org> wrote:> > Does anyone know the best way to display a list of rows grouped by month > > in a view? > > > An example would be: > > > December > > > Dec. 15, Saturday at 8:30pm: Some Field > > > Dec. 9, Sunday at 8:30pm: Some Field > > > Dec. 5, Wednesday at 8:30pm: Some Field > > > November > > > Nov. 15, Saturday at 8:30pm: Some Field > > group_by() {|element| ...} > > Collect an enumerable into sets, grouped by the result of a block. Useful, > for example, for grouping records by date. > > e.g. > > latest_transcripts.group_by(&:day).each do |day, transcripts| > p "#{day} -> #{transcripts.map(&:class) * '', ''}" > end > "2006-03-01 -> Transcript" > "2006-02-28 -> Transcript" > "2006-02-27 -> Transcript, Transcript" > "2006-02-26 -> Transcript, Transcript" > "2006-02-25 -> Transcript" > "2006-02-24 -> Transcript, Transcript" > "2006-02-23 -> Transcript"--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks Philip. Very helpful. -- 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 -~----------~----~----~----~------~----~------~--~---
ebrad, that''s great! Thanks so much. -- 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 -~----------~----~----~----~------~----~------~--~---
> Does anyone know the best way to display a list of rows grouped by month > in a view? > > An example would be: > > December > > Dec. 15, Saturday at 8:30pm: Some Field > > Dec. 9, Sunday at 8:30pm: Some Field > > Dec. 5, Wednesday at 8:30pm: Some Field > > November > > Nov. 15, Saturday at 8:30pm: Some Fieldgroup_by() {|element| ...} Collect an enumerable into sets, grouped by the result of a block. Useful, for example, for grouping records by date. e.g. latest_transcripts.group_by(&:day).each do |day, transcripts| p "#{day} -> #{transcripts.map(&:class) * '', ''}" end "2006-03-01 -> Transcript" "2006-02-28 -> Transcript" "2006-02-27 -> Transcript, Transcript" "2006-02-26 -> Transcript, Transcript" "2006-02-25 -> Transcript" "2006-02-24 -> Transcript, Transcript" "2006-02-23 -> Transcript" --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---