Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Callbacks being called twice with nested attributes

#3866

With a blog project with post-comments, using rails 2.3.5:

class Post < ActiveRecord::Base
  has_many :comments
  
  accepts_nested_attributes_for :comments
  ...
end

class Comment < ActiveRecord::Base
  belongs_to :post
  ...
end

So, printing out all callbacks:

def callback_name
  p "#{callback_name} - #{object_id}"
  ...
end

each callback of comments is called twice, including save.

"post_before_validation - 2174878780"
"post_before_validation_on_update - 2174878780"
"comment_before_validation - 2174811020"
"comment_before_validation_on_update - 2174811020"
"comment_after_validation - 2174811020"
"comment_after_validation_on_update - 2174811020"
"comment_before_validation - 2174811020"
"comment_before_validation_on_update - 2174811020"
"comment_after_validation - 2174811020"
"comment_after_validation_on_update - 2174811020"
"post_after_validation - 2174878780"
"post_after_validation_on_update - 2174878780"
"post_before_save - 2174878780"
"post_before_update - 2174878780"
"comment_before_save - 2174811020"
"comment_before_update - 2174811020"
"comment_after_update - 2174811020"
"comment_after_save - 2174811020"
"comment_before_save - 2174811020"
"comment_before_update - 2174811020"
"comment_after_update - 2174811020"
"comment_after_save - 2174811020"
"post_after_update - 2174878780"
"post_after_save - 2174878780"

Reported by Fabio Yamate · February 5th, 2010 @ 08:36 PM

State: duplicate
Milestone: none
Assigned to: José Valim José Valim
Importance: Low

Activity

  1. José Valim
    José Valim
    • State changed from new to resolved

    This was already fixed on both master and 2-3-stable branches according to this ticket: #3575. Thanks!

    February 6th, 2010 @ 09:43 AM

  2. José Valim
    José Valim
    • State changed from resolved to duplicate

    February 6th, 2010 @ 09:43 AM

  3. Ryan Bigg
    Ryan Bigg
    • Tag cleared.
    • Importance changed from to Low

    Automatic cleanup of spam.

    October 9th, 2010 @ 09:47 PM

  4. bingbing