/ Published in: Rails
Allows iteration through the main array, with subarrays with the records for each group.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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 }}