Forum: Ruby on Rails RE: grouped output

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Campano, David (Guest)
on 2006-05-03 21:07
(Received via mailing list)
I think you will want to use the new group_by function.  Here is an

p = Person.find(:all)
grouped = p.group_by(&:center)

Now 'grouped' is a hash where the key is 'center' and the value of the
hash is the groups of people.

Now you can do:

grouped.each do |center, person|
	puts center
	person.each do |p|
		List out the people

Further reading at:
Jin L. (Guest)
on 2006-05-03 21:07
(Received via mailing list)
Thanks for the link David, will check it out.

Thanks again,

This topic is locked and can not be replied to.