Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change devise message "Email has already been taken"

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?

like image 954
Arif Avatar asked Jul 10 '13 12:07

Arif


1 Answers

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

like image 65
Santhosh Avatar answered Oct 02 '22 19:10

Santhosh