I have a class, Teacher, that has multiple integer columns:
t.integer :a_students
t.integer :b_students
t.integer :c_students
t.integer :d_students
t.integer :f_students
And I have a view that loops through all the teachers and states how many students are in their class. Now although I could add all the students in the view, just to make it look nicer I want to offload adding all the students into the model. I have the following model method:
def count_students( teacher_id )
t = Teacher.find(teacher_id)
total = t.a_students + t.b_students + t.c_students + t.d_students + t.f_students
total
end
If I'm not mistaken, I shouldn't be accessing model methods from the view - that should be left to the controller. But since its looping through, I'm a little lost on what to do in this case. Any Ideas?
Thanks Ben