Return to Snippet

Revision: 29732
at August 4, 2010 03:13 by insanedreamer


Initial Code
User.order(:country_id).group_by(&:country_id).each { |country| country.each { |usergroup| if usergroup.is_a?(Array) then usergroup.each { |user| puts user.name  } else puts Country.find(usergroup).name end }}

Initial URL


Initial Description
Allows iteration through the main array, with subarrays with the records for each group.

Initial Title
returning an array of objects grouped by a field (in sub groups)

Initial Tags


Initial Language
Rails