ruby on rails 3 - How do I calculate a value in a model based on children of that model in rails3? -


I'm new to rail and I can think of several ways to solve this problem, but I I want to "Rail" route My problem is that I have a model - examination - which: There are many questions. I want to write a function in the examination model which will calculate the score for the examination (and store it in the examination model) Will). To do this, I need to read data from exam items.

Any tips or links for documents will be highly appreciated.

As long as you do not write anything about your data structure, think that your The error of each question is boolean, the correct field and the integer total_score field in your exam is found. Therefore, after checking, it should count all the answers with the correct answer:

  class exam < ActiveRecord :: Base has_many: questions before_save: set_score def set_score total_score = questions.where (: true = & gt; true). Count & End    

Comments