更新时间:2023-12-01 21:44:10
更改code到以下
before_save :calculate_and_save_budget_contingency
def calculate_and_save_budget_contingency
self.total_contingency = self.budget_contingency + self.risk_contingency
end
原因是 - 如果你运行在保存 after_save的
您在无限循环结束:保存after_save的回调函数调用,调用保存它调用after_save的,这..
Reason for that is - if you run save in after_save
you end up in infinite loop: a save calls after_save callback, which calls save which calls after_save, which...
在总体上是明智的,你使用后只能保存更改相关的模型等。
In general it's wise you use after save only for changing associated models, etc.