2010-04-24 88 views

回答

4

generate_full_message该文档可能会使用:

任何语言环境的默认FULL_MESSAGE格式为“{{attribute}} {{message}}”。可以通过将其存储为关键字翻译来指定特定于语言环境的默认full_message格式:“activerecord.errors.full_messages.format”。

此外,可以通过存储“activerecord.errors.full_messages.[message_key]”的翻译来指定验证特定的错误消息格式。例如。任何使用以下内容的验证的full_message格式都可以存储为:“activerecord.errors.full_messages.blank”,作为消息密钥(如validates_presence_of)。

因为由验证所使用的消息密钥可在validates_ *类宏观层面上覆盖一个可以自定义格式FULL_MESSAGE针对任何特定的验证:

# app/models/article.rb 
class Article < ActiveRecord::Base 
    validates_presence_of :title, :message => :"title.blank" 
end 

# config/locales/en.yml 
en: 
    activerecord: 
    errors: 
     full_messages: 
     title: 
      blank: This title is screwed! 

在你的情况,因为你正在使用的默认{{attribute}} {{message}}格式,您收到属性的“电子邮件”和邮件的“您的电子邮件无效”。您可以将:message参数更改为“不是有效格式”,并且您应该收到“电子邮件不是有效格式”。这是快速修复。如果你想完全自定义它,你可以使用上面的locale方法。