I have created a model that looks like this:
class Parent < ActiveRecord::Base
attr_accessible :child, :child_id
has_one :child, :class_name => 'Child', :autosave => true, :inverse_of => :parent
#parent's validations
validates_associated :child
end
And the child model is like:
class Child < ActiveRecord::Base
attr_accessible :parent, :parent_id
belongs_to :parent, :inverse_of => :child
validates_presence_of :parent
#Other custom validations...
end
When I am at the new child's page, if the user does not choose a previously created parent for the child, I want to force him to create one at the same time he creates the child. It's working fine if the user fills in all the data correctly for the child and the parent, but if the parent has any validation issue on a given field, the only message I get is: "Parent cannot be blank"
I wanted to show to the user the same message it would show if he was creating the Parent alone. That should be something like: "Field X of Parent is too short".
Is it possible, using validates_associated or with some similar helper?
Thanks in advance!