class Parent has_one :child accepts_nested_attributes_for :child end class Child belongs_to :parent end
Using the nested form of the object, I need to add some additional checks to the child model. They do not always run on Child, so I cannot put them in the validate method in Child. It seems reasonable to do validation in the verification method in Parent, but I am not able to correctly add error messages.
It works:
class Parent ... def validate errors[ :"child.fieldname" ] = "Don't be blank!" end
But we are losing nice things like I18n highlighting and CSS in the error field.
This does not work:
def validate errors.add :"child.fieldname", :blank end
source share