There is nothing in rails that can validate an associated record
exists for a belongs_to relationship.
But you can use Josh S.'s fantastic validates_existence_of plugin
that does check whether the associated record exists or not
Check out his post here here
On Jul 5, 8:44ï¿½am, Learn by Doing [email protected]
I’ve found that:
works just fine.
From what I have been able to tell, validates_associated is meant for
when you are constructing two or more associated models at the same
time, and you don’t want to save them unless both validate. So your
user validates would contain:
which would run all the validations for the address model. However, you
can’t at the same time have a
line in the address model, because that will cause an infinite recursion
loop of validations.