I have a Rails Table, called Sales, that I would like to render in a sequence of HTML tables on a single HTML page.
The Sales Table contains a list of sales transactions made by SalesPeople (salesperson_id is a field within each Sales record), and I would like to list each of their Sales records grouped in HTML tables, by salesperson_id. Similar to this:
Sales Person : Bob
*PRODUCT* *QUANTITY*
Widgets 17
Cogs 5
Screws 100
Sales Person : Jim
*PRODUCT* *QUANTITY*
Bozzles 49
Widgets 20
Screws 250
Flurbs 22
Now, my first thoughts were that I would ‘find_all’ sales transactions meeting my criteria, and then loop through the returned array, and rendering each SalesPerson using a _partial, but I’m aware I can only perform one render per result.
Is it possible to achieve this using a single render, do I need some HTML / JavaScript magic, or is there another solution?
Thanks.
OK, I figured out a way to achieve what I want to achieve by using group_by, with help from this RailsCast,
http://railscasts.com/episodes/29-group-by-month (#29 of a brilliant series)
So, I use group_by to group the sales by salesperson_id, then in my view,