ruby on rails - Accessing nested models in an after_create callback -


i have model accepts_nested_attributes_for child model:

class parentresource < activerecord::base   has_many :child_resources    accepts_nested_attributes_for :child_resources    after_create :log_child_resources    private   def log_child_resources     logger.debug "child resources: #{child_resources}"   end end 

unfortunately, after_create callback doesn't log child_resources, when child_resources provided nested attributes. these child_resources saved , accessible, @ point cannot examine them child_resources. presumably because parent_resource saved before nested children, there not yet children in associative array.

so question is: @ point in creation cycle, there way access child_resources?

well, can try , log each child resource in own after_create callbacks. since these records aren't created yet, can log supplied attributes:

logger.debug "child resources: #{child_resources_attributes}" 

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -