Given the ratio expressed below:
class Parent < ActiveRecord::Base
has_many :children, :dependent => :destroy
accepts_nested_attributes_for :child
end
class Child < ActiveRecord::Base
belongs_to :parent
validates :name, :presence => true
end
Suppose we have a parent with several children, one or more of which have errors that cause parent.valid? to return false.
parent = Parent.new
parent.build_child(:name => "steve")
parent.build_child()
parent.valid?
Is there a way to access the child that caused errors while viewing the parent.errors object?
source
share