ruby on rails - Custom message with validates presence of not working -
my user
model contains following:
validates :password_digest, :presence => true, :message => "the password has 6 or more characters long" def password=(password) self.password_digest = bcrypt::password.create(password) if password.length >= 6 end
the issue message
in validates
isn't working. unknown validator: 'messagevalidator'
error. assumed way presence
validation worked check if password_digest
nil
, had password
had length less 6. want solution elegant, attempted. have solved 1 way, appreciate understanding why i'm trying isn't working, , there way make work.
what got work was:
validate |user| user.errors['password'] = "can't less 6 characters" if user.password_digest.nil? end
this due how validates
method works. assumes you're looking messagevalidator
when specify :message
key in hash passed validates
.
this can solved reconstructing query follows:
validates :password_digest, :presence => { :message => "the password has 6 or more characters long" }
Comments
Post a Comment