RE: grouped output

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

Thanks for the link David, will check it out.

Thanks again,

Jin

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