I have a standard master-detail relationship between two models in a RoR application. The detail records contain four boolean fields indicating presence / absence of something.
When I display the detail records I want to add a summary indicating the number of records which have their boolean value set to True for each of the four boolean fields.
For example: Date | Boolean Field 1 | Boolean Field 2 | etc 2009/08/29 | T | T | 2009/08/30 | T | F | 2009/08/31 | F | T | 2009/09/01 | F | T |
Total: 4 2 3
I tried using something like @entries.count(["Boolean Field 1", true]) The way I see it, there are two ways to calculate these values: one at the model by executing an SQL query (ugly) or at the view level by using a counter (ugly again.) Is there some other way to achieve what I want?
Thank you for your time,
Angelos Arampatzis