Devise - change error message without hardcoded in yml

230 views Asked by At

I authenticate user by Devise with keys config.authentication_keys = [ :email , :company_id ]

In config/locales/devise.en.yml, the fail message is configured:

    invalid: "Invalid %{authentication_keys} or password."

So, wrong authentication with message (what I don't like):

    Invalid email, company_id or password.

How can I change the message like this

    Invalid email, company or password.

without hardcoded invalid: "Invalid email, company or password." in devise.en.yml:

1

There are 1 answers

1
nesiseka On

Something like the following should work:

config.authentication_keys = [ :email , :company_id ]
config.authentication_key_labels = config.authentication_keys.join(', ').gsub('_id','')

invalid: "Invalid %{authentication_key_labels} or password."

Edit: since devise itself doesn't have a place to store them, I can't find a way to do what you require. Editing strings in the yaml file itself is not possible.