[Rails] grouped output

Jin Lee
2006-05-03T15:30:37Z

Thanks for the link David, will check it out.

Thanks again,

Jin

On 5/3/06, Campano, David <David_Campano@bcbst.com>
wrote:
> 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/new-in-rails-enumerable-group_by-and-array-in_groups_of
>
> -----Original Message-----
> From: rails-bounces@lists.rubyonrails.org
> [mailto:rails-bounces@lists.rubyonrails.org]On Behalf Of Jin Lee
> Sent: Wednesday, May 03, 2006 10:05 AM
> To: rails@lists.rubyonrails.org
> Subject: [Rails] grouped output
>
>
> hello,
>
> Suppose I have a table that looks like this:
>
> center name email
> Health Jon jon@test.com
> Health Bob bob@test.com
> Admin Jane jan@test.com
> Admin Jill jill@test.com
>
> I would like the output to look like this:
>
> Health
> Jon jon@test.com
> Bob bob@test.com
> Admin
> Jane jan@test.com
> Jill jill@test.com
>
> when i using cold fusion, this was easy via a tag called cfoutput.
> when i was using java, this was difficult, and i had to put some extra
> conditionals in the table. is there an easy way to do this in rails?
>
> thanks,
> Jin
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
> Please see the following link for the BlueCross BlueShield of Tennessee
E-mail
> disclaimer:  http://www.bcbst.com/email_disclaimer.shtm
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>