I know I\'ve seen this before but I can\'t find anything now. I want to group a query by a certain column and be able to display how many are in each group. I got the first part
You can do count on line_items which will return you an ordered hash of device_id and count.
count
line_items
device_id
@project.line_items.group(:device_id).count