定制Rails 3中的Devise错误消息? [英] Customizing Devise error messages in Rails 3?
问题描述
< div class =field<%if resource.errors [:email] .present?%> error<%end%>>
<%= f.label:email,电子邮件:%>< br />
<%如果resource.errors [:email] .present? %GT;
< ul>
<%resource.errors [:email] .each do | msg | %GT;
< li><%= msg%>< / li>
<%end%>
< / ul>
<%end%>
<%= f.text_field:email,:class => text%>
< / div>
但是当电子邮件有问题时,显示的消息如下:无效
。这不是非常用户友好,但我找不到这个消息被设置的位置。它似乎不在devise.en.yml中,但也许我忽略了某些东西。
任何想法,我可以自定义错误消息?
谢谢!
这些验证都定义在validations 模块,并使用默认的Rails错误消息。
您可以在模型中覆盖这些。
validates_format_of:email,,with => email_regexp ,:allow_blank => true,message =>此处的新错误消息
I am using devise to handle authentication. Overall I like it, but I'd like to customize the error display a bit. Right now I've got the following in my view.
<div class="field <% if resource.errors[:email].present? %>error<% end %>">
<%= f.label :email, "Email:" %><br />
<% if resource.errors[:email].present? %>
<ul>
<% resource.errors[:email].each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
<% end %>
<%= f.text_field :email, :class => "text" %>
</div>
But when there is a problem with the email, the message displayed is as follows: is invalid
. That's not very user friendly, but I can't find where this message is being set. It doesn't appear to be in devise.en.yml, but perhaps I'm overlooking something.
Any idea where I can customize the error messages?
Thanks!
These validations are all defined in the validations module, and use the default Rails error messages.
You can override these in your model.
validates_format_of :email, :with=>email_regexp, :allow_blank => true, :message=>"new error message here"
这篇关于定制Rails 3中的Devise错误消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!