改变设计消息“电子邮件已经被接收”。 [英] Change devise message "Email has already been taken"

查看:235
本文介绍了改变设计消息“电子邮件已经被接收”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Rails应用程序的红宝石中使用了devise宝石。在用户注册时,如果已经存在一封电子邮件,则存在默认消息电子邮件已被接收。



我已在en.yml中更改了此消息

 活动记录:
错误:
消息:
已采取:使用相同电子邮件的用户已存在。请尝试和另一个电子邮件地址。

鉴于我使用过:

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

现在我收到的消息是



<$ p $ p> 已存在具有相同电子邮件的电子邮件用户。请尝试使用其他电子邮件地址。

问题是在开始处附加了电子邮件。



还有其他方法可以更改此默认消息吗?

解决方案

将邮件格式更改为

  zh:
错误:
格式:%{message}

默认值为%{attribute}%{message}



更新



还有另一种解决方案。我知道这是一种解决方法,但是可以解决。.
删除现有的验证,并添加一个自定义验证。

  validate:email_uniqueness 

def email_uniqueness
self.errors.add(:base,'使用相同电子邮件的用户已经存在。请尝试使用其他电子邮件地址。')如果User.where( :email => self.email)。
结尾

注意:
在执行更新


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?

解决方案

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

这篇关于改变设计消息“电子邮件已经被接收”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆