Devise: How to Override Devise Error Messages on Password Change

How can I customize Devise error message?

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

Customize Devise Passwords error message

Add a new locale having the following structure:

en:
devise_token_auth:
passwords:
user_not_found: "Your custom message"

This message will be displayed when an invalid email is passed in the forgot password form.

Originally this message comes from the devise_token_auth gem. But if you have the same locale in your locale files, it will override the gem's locale.

It doesn't matter which *.en.yml file you will put this locale into. It can be devise.en.yml, or you can add a new file called devise_token_auth.en.yml. Only the structure matters.

How to change Validation error messages in devise in Rails 5

You'll have to override the devise.en.yml file in the following manner

en:
activerecord:
errors:
models:
user:
attributes:
password:
too_short: "Password is too short (minimum is %{count} characters)"

How to edit error messages in devise

Devise Generates a devise.en.yml file in config/locales/
If you need your error messages to be in another language such as Spanish, replace your devise.en.yml with this file:

devise.es.yml

es:
errors:
messages:
expired: "ha expirado, por favor pide una nueva"
not_found: "no encontrado"
already_confirmed: "ya fue confirmada. Intenta ingresar."
not_locked: "no ha sido bloqueada"
not_saved:
one: "Ha habido 1 error:"
other: "Han habido %{count} errores:"

devise:
failure:
already_authenticated: 'Ya iniciaste sesión.'
unauthenticated: 'Tienes que registrarte o iniciar sesión antes de continuar.'
unconfirmed: 'Tienes que confirmar tu cuenta antes de continuar.'
locked: 'Tu cuente está bloqueada.'
invalid: 'Email o contraseña inválidos.'
invalid_token: 'Token de autentificación inválido.'
timeout: 'Tu sesión ha expirado. Inicia sesión nuevamente.'
inactive: 'Tu cuenta aun no ha sido activada.'
sessions:
signed_in: 'Iniciaste sesión correctamente.'
signed_out: 'Cerraste sesión correctamente.'
passwords:
send_instructions: 'Recibirás un email con instrucciones para reiniciar tu contraseña en unos minutos.'
updated: 'Tu contraseña fue cambiada correctamente. Has iniciado sesión.'
updated_not_active: 'Tu contraseña fue cambiada correctamente.'
send_paranoid_instructions: "Si tu email existe en el sistema, recibirás instrucciones para recuperar tu contraseña en él"
confirmations:
send_instructions: 'Recibirás instrucciones para confirmar tu cuenta en tu email en unos minutos.'
send_paranoid_instructions: 'Si tu email existe en el sistema, recibirás instrucciones para confirmar tu cuenta en tu email en unos minutos.'
confirmed: 'Tu cuenta fue confirmada. Has iniciado sesión.'
registrations:
signed_up: 'Bienvenido! Te has registrado correctamente.'
signed_up_but_unconfirmed: 'Te hemos enviado un email con instrucciones para que confirmes tu cuenta.'
signed_up_but_inactive: 'Te has registrado correctamente, pero tu cuenta aun no ha sido activada.'
signed_up_but_locked: 'Te has registrado correctamente, pero tu cuenta está bloqueada.'
updated: 'Actualizaste tu cuenta correctamente.'
update_needs_confirmation: "Actualizaste tu cuenta correctamente, pero tenemos que revalidar tu email. Revisa tu correo para confirmar la dirección."
destroyed: 'Adiós, tu cuenta ha sido eliminada. Esperamos verte de vuelta pronto!'
unlocks:
send_instructions: 'Recibirás un email con instrucciones para desbloquear tu cuenta en unos minutos'
unlocked: 'Tu cuenta ha sido desbloqueada. Inicia sesión para continuar.'
send_paranoid_instructions: 'Si tu cuenta existe, recibirás instrucciones para desbloquear tu cuenta en unos minutos'
omniauth_callbacks:
success: 'Te autentificaste correctamente con tu cuenta de %{kind}.'
failure: 'No pudimos autentificar tu cuenta de %{kind} por la siguiente razón: %{reason}.'
mailer:
confirmation_instructions:
subject: 'Instrucciones de confirmación'
reset_password_instructions:
subject: 'Instrucciones de cambio de contraseña'
unlock_instructions:
subject: 'Instrucciones de desbloqueo'

UPDATE

es:
activerecord:
errors:
models:
user:
attributes:
email:
blank: "El email no puede estar vacio"

Modify Devise reset password error text

Add this to your config/locals/en.yml and change it to what you want

en:
activerecord:
errors:
models:
user:
attributes:
password:
confirmation: "Password does not match"
too_short: "is too short (minimum is %{count} characters)"
attributes:
user:
password: "Password"

Devise, customizing the error messages?

http://ar.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html

validates_presence_of(*attr_names)

Configuration options:
message - A custom error message (default is: "can‘t be blank").

As for the built in names customisation, this thread can help

Rails3: Devise internationalization does not localize "Password confirmation" and others

(to extend)

activerecord:
attributes:
user:
email: "your_way_of_email"
password: "your_way_of_password"
password_confirmation: "your_way_of_password_confirmation"

Rails will then humanize them

Customizing Devise error messages in Rails 3?

These validations are all defined in the validations module, and use the default Rails error messages.

You can override these in your model.

validates_format_of :email, :with=>email_regexp, :allow_blank => true, :message=>"new error message here" 


Related Topics



Leave a reply



Submit