2

i am a newbie to ruby and rails.
I've tried to create authentication with has_secure_password.
Everything was good till the moment when i tried to override an error message for password_digest field.
I 've search about it but all questions are about "how to change 'Password digest cant by blank' to 'Password cant by blank' "
I know that this can be change in config/locales/en.yml but what if i want change the whole message.
Suppose i need a message like "password digest cant by blank , please fill it" or message in another language.
Is that possible?

Karol85
  • 275
  • 1
  • 4
  • 13

1 Answers1

1

I realize that this post is several years old, but it's still the one that comes up first in regards to this question. That being said, as seen in the link here if you provide has_secure_password with the options argument, and inside the object, put validations: false then you can make your own validation messages. Be aware that this will cancel all validation methods, so you will have to make ones in regards to length and confirmation.

For example,

has_secure_password(options={validations:false}

validates :password, presence: {message: "Password was not entered"}

This will now show "Password was not entered" upon failing the validation.

Lin Du
  • 88,126
  • 95
  • 281
  • 483
TimeSmash
  • 11
  • 1