I am having a model Evaluation
that has many sub evaluations (self refential)
class Evaluation < ApplicationRecord
has_many :sub_evaluations, class_name: "Evaluation", foreign_key: "parent_id", dependent: :destroy
before_save :calculate_score
def calculate_score
# do something
end
end
I am creating and updating evaluation with sub evaluations as nested attributes.
calculate_score
method is triggered on sub evaluation creation but not while updating. I have tried before_update
and after_validation
. But nothing seems to be working.
Evaluation form
= form_for @evaluation do |f|
...
= f.fields_for :sub_evaluations do |sub_evaluation|
...
What seems to be the issue?