Aakanksha
Aakanksha

Reputation: 976

Customize Devise Passwords error message

I've a project that implements devise and I'm having trouble overriding the Passwords controller's messages.

When a wrong email address is entered by the user, Devise by default gives

Unable to find user with email {email}

I cant find the key to override this message in the devise.en.yml and can't find anything with the similar message on the devise repo as well.

Do I have an option other than to override the controller? Any help is appreciated.

Thanks

Upvotes: 0

Views: 1869

Answers (2)

chumakoff
chumakoff

Reputation: 7054

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.

Upvotes: 2

fabOnReact
fabOnReact

Reputation: 5942

as described in the following link you can generate the devise controller with

rails generate devise:controllers user

then you can over-ride the create or update action. If you include super in the new action, it will call the parent controller action and then execute the code.

You can also over-ride the devise messages as explained in this post, you just need to create that locale in your settings

en:
  devise_token_auth:
    sessions:
      not_confirmed: "your message overwritten"

Upvotes: 0

Related Questions