Ari*_*rif 8 ruby-on-rails devise
我在我的ruby on rails应用程序中使用了devise gem.在用户注册时,如果已存在电子邮件,则会显示默认消息"已收到电子邮件".
我在en.yml中更改了此消息
activerecord:
errors:
messages:
taken: "User with same email already exists. Please try with another email address."
Run Code Online (Sandbox Code Playgroud)
在视图中我使用过:
<div class="notice"><%= devise_error_messages! %></div>
Run Code Online (Sandbox Code Playgroud)
现在我得到的信息是
"Email User with same email already exists. Please try with another email address."
Run Code Online (Sandbox Code Playgroud)
问题是在开始时附加了"电子邮件".
有没有其他方法可以更改此默认消息?
将邮件格式更改为
en:
errors:
format: "%{message}"
Run Code Online (Sandbox Code Playgroud)
默认是 "%{attribute} %{message}"
UPDATE
还有另一种解决方案.我知道这是一个解决方法,但这里去了..删除现有的验证,并添加一个自定义验证.
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
Run Code Online (Sandbox Code Playgroud)
注意:在进行更新时,您应该考虑现有用户
| 归档时间: |
|
| 查看次数: |
4787 次 |
| 最近记录: |