Remember_me
Remember_me

Reputation: 283

How can I customize Devise error message?

In my password change controller, I m allowing users to change their password provided they have valid password request token.

However after they've already used one it becomes invalid and so if they want to re-use it again, the user gets an error on the model:

Reset password token is invalid

This is from Devise itself. How can modify this message to be :

User reset password token already used

If I cannot change the message via some configuration, then is there a method that would allow me to check if the token is valid or not?

So that I can manually render this message in this case

Upvotes: 1

Views: 2782

Answers (3)

Milind
Milind

Reputation: 5112

If you are looking to change/customize devise error/flash messages...simply change the devise.en.yml file show below at config/locals/devise.en.yml location

######example
en:
  devise:
    confirmations:
      ##OLD => confirmed: "Your email address has been successfully confirmed."
      confirmed: "Your are not a confirmed user.Kindly Confirm your Email Id"

Hope this helps ;)

Upvotes: 0

mechnicov
mechnicov

Reputation: 15248

It's not Devise, but ActiveModel error message:

person.errors.full_message(:name, 'is invalid') # => "Name is invalid"

And you can overwrite it in your locale file.

en:
  activerecord:
    attributes:
      user:
        reset_password_token: User reset password token
    errors:
      models:
        user:
          attributes:
            reset_password_token:
              invalid: already used

Upvotes: 5

Zavitoski
Zavitoski

Reputation: 403

You can customize the error messages in Devise by setting up your locale file (as mentioned in the documentation here)

You can find more on the use of locale files here: https://github.com/plataformatec/devise/wiki/I18n

Upvotes: 0

Related Questions