Reputation: 1399
I am using devise gem in my ruby on rails application. On user signup if an email already exists then there is a default message "Email has already been taken".
I have changed this message in en.yml
activerecord:
errors:
messages:
taken: "User with same email already exists. Please try with another email address."
In view i have used:
<div class="notice"><%= devise_error_messages! %></div>
Now the message i am getting is
"Email User with same email already exists. Please try with another email address."
The problem is that "Email" is appended at the start.
Is there any other way to change this default message?
Upvotes: 9
Views: 7630
Reputation: 29144
Change format of the message to
en:
errors:
format: "%{message}"
Default is "%{attribute} %{message}"
UPDATE
There is another solution. I know this is a work around, but here goes.. Remove the existing validation, and add a custom one.
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 should consider the existing user, while doing an update
Upvotes: 10