Forum: Ruby on Rails RE: grouped output

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E94ca0face81fe54d0486b397ea3412d?d=identicon&s=25 Campano, David (Guest)
on 2006-05-03 19:07
(Received via mailing list)
I think you will want to use the new group_by function.  Here is an
example:

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
	end
end

Further reading at:
http://weblog.rubyonrails.org/articles/2006/03/01/...
E2489efc6ec10ec818b71965909ea109?d=identicon&s=25 Jin Lee (Guest)
on 2006-05-03 19:07
(Received via mailing list)
Thanks for the link David, will check it out.

Thanks again,

Jin
This topic is locked and can not be replied to.