別のモデルオブジェクト(子)にhas_manyアソシエーションを持つモデルオブジェクト(たとえば親)があります。
class Parent < ActiveRecord::Base
has_many :children
accepts_nested_attributes_for :children
end
class Child < ActiveRecord::Base
belongs_to :parent
end
親では、before_updateコールバックにコードを追加して、その子に基づいて計算された属性を設定します。
私が遭遇した問題は、メソッドParent.update(id、atts)を使用して、新しい子のattsを追加すると、attsコレクションに追加されたものがbefore_update中に使用できないことです(self.childrenは古いコレクションを返します) 。
accepts_nested_attributes_forをいじらずに新しいものを取得する方法はありますか?