Change the "Email has already been done" error message.

I use an ingenious stone in my ruby ​​on a rails application. When registering a user, if the mail already exists, the default message β€œEmail has already been done” appears.

I changed this post in en.yml

activerecord: errors: messages: taken: "User with same email already exists. Please try with another email address." 

In the field of view that I used:

 <div class="notice"><%= devise_error_messages! %></div> 

Now the message I receive is

 "Email User with same email already exists. Please try with another email address." 

The problem is that the "Email" is added at the beginning.

Is there any other way to change this default message?

+6
source share
1 answer

Change the message format to

 en: errors: format: "%{message}" 

The default value is "%{attribute} %{message}"

UPDATE

There is another solution. I know this is work, but here it goes ... Delete the existing check and add it.

 validate :email_uniqueness def email_uniqueness self.errors.add(:base, 'User with same email already exists. Please try with another email address.') if User.where(:email => self.email).exists? end 

Note: You must review the existing user when performing the upgrade.

+7
source

Source: https://habr.com/ru/post/949117/


All Articles