In a Rails app I’ve got 1-to-many relationships where I want to summarize on webpage dashboard:
reservation_id item_id quantity out_date_time back_date_time
Reservation_ID Customer Name Item 1 Quantity (Sum) Item 2 Quantity (Sum) Item 3 Quantity (Sum) out_date_time (Min) back_date_time (Max)
Item 1,2,3 are the most common items that are reserved so want the admin to be able to see them at glance. In general, most people will reserve only 1 item so want to display start/end date in the table.
My question: How to best pull this data/display and write automated tests for it?
- Is there some active record query helpers that would make this
- Do I write raw SQL code in my controller?
- Do I pull simply join the 2 tables and write ruby methods to summary the data?
If so where do I put these methods and call them from?
- Is there a different method I am
not thinking of?