1

I use accepts_nested_attributes in my model parent and the parent model has belongs_to association with children model. I am trying to use callbacks in my children model (after_update, after_create).When update_attributes used in parents_controller to update the parent record.The callbacks after_create is working fine but after_update is not triggering.

class Parent
  accepts_nested_attributes :children
  belongs_to :children
end
class Children
  before_save :saving
  after_update :test
  has_many :parents
end

Help me to solve this problem?

Achaius
  • 5,904
  • 21
  • 65
  • 122
  • Can you include the line, which makes the update? –  May 29 '13 at 11:04
  • @santhosh @parent.update_attributes!(params[:parent]) – Achaius May 29 '13 at 11:09
  • Does params[:parent] contain children attributes ? –  May 29 '13 at 12:12
  • @santhosh yes,It contains children attributes. – Achaius May 29 '13 at 12:26
  • `class Children; accepts_nested_attributes :parent; end` and remove `accepts_nested_attributes :children` – itsnikolay May 29 '13 at 12:33
  • The `accepts_nested_attributes` method is meant to work for the class with the has_many/has_one relationship. It won't work on your Parent class which maintains the `belongs_to` association. See http://stackoverflow.com/questions/1313149/getting-fields-for-and-accepts-nested-attributes-for-to-work-with-a-belongs-to-r – rossta May 29 '13 at 12:46

0 Answers0