Re: [Rails] Create a new hash from an existing table

2012-02-11 Thread Everaldo Gomes
On Sat, Feb 11, 2012 at 11:50 PM, Everaldo Gomes wrote: > Hi! > > Take a look at: > > http://www.ruby-doc.org/core-1.9.3/Enumerable.html#method-i-group_by > > and > > http://www.ruby-doc.org/core-1.9.3/Enumerable.html#method-i-collect > > I think they could help. > > E.g: > > hash = Time.all.colle

Re: [Rails] Create a new hash from an existing table

2012-02-11 Thread Everaldo Gomes
Hi! Take a look at: http://www.ruby-doc.org/core-1.9.3/Enumerable.html#method-i-group_by and http://www.ruby-doc.org/core-1.9.3/Enumerable.html#method-i-collect I think they could help. E.g: hash = Time.all.collect { |t| [ t.date , t.hour ] }.group_by { |date,hour| date.strftime("%-m/%-d/%Y

[Rails] Create a new hash from an existing table

2012-02-11 Thread edward michaels
I have an active record Times table with a date column and an hour column. The hours are unique but the dates can have many hours. How would I create a hash that mapped a date key to its hours? Something like: hours_per_date['2/14/2012'] => ['6:00', '8:00', '11:00', '2:00'] Thanks -- You rec