Displaying Data by Month

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.

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”

Thanks Philip. Very helpful.

yup. Ryancasts to the rescue - http://railscasts.com/episodes/29

ebrad, that’s great! Thanks so much.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs