I just started using rails and am trying to learn fast but I am
confused with what I have read about using group_by and could use some
help please.
I have two tables - students and evaluations
students has many evaluations and evaluations have one student
The student record has id, name, and grad_year columns
The evaluations record has id, student_id, eval_date and many boolean
columns.
I would like to get a report of the sum of each of the boolean columns
for evaluations by grad_year
I would also like to include only items that have a sum > 0 (i.t. if
item1 is always false, then sum is zero and it should not be included
in the report).
I have tried a bunch of things but cannot seem to figure it out.
My last attempt was close, but I am not sure if it is best nor what to
put in the view to display the actual items.
My controller had something like the following (abbreviated to save
space):
@evaluations = Student.all(:joins => :evaluations, :select
“students.*, sum(evaluations.item1) as sum_eval1, sum
(evaluations.item2) as sum_item2”, :group => “students.grad_year”)
I can get this query to work in the console, but am not sure how to
utilize the results in the view.
Thanks, any help is appreciated.