How do I validate a name consisting of two columns with simple validate call, or with a validator method?
I have a name consisting of two column, firstname and surname. A record is valid only when firstname + surname is unique.
If I add firstname: "lala la", surname: "le li lo" it is valid because it is the only one.
If I enter firstname: "lala", surname: "la le li lo", and the concatenation of firstname and surname is the same in both examples, the second shouldn’t be valid.
I cannot find simple way to do this.
I tried things like:
validates_uniqueness_of :firstname, :surname, :scope => {:firstname, :surname}
or combinations of this, but that didn’t work.
firstname=”lalla”, surname= “leli”
and
firstname=”la”, surname= “llaleli” are different,so following validation can’t validate it
try this
idea is that compute full name(in a callback like before_validation) and store it in table(So you need another column) now add validation on that column