Given a model with the validation below, a produced error will
be attached to the hash key :validate_username_unique instead of to
:username.
validates_with_method :username, :validate_username_unique
def validate_username_unique
if new_record? || changed?(:username)
if self.class.by_username( :key => self.username, :limit => 1).blank?
return true
else
return [false, "Username has already been taken"]
end
else
return true
end
end
# note: changed?(field) is a method added to the class, that is
tested and works
Here is what the error inspection looks like:
<CouchRest::Validation::ValidationErrors:0x23a2e18
@errors={:validate_username_unique=>["Username has already been
taken"]}>