2016-04-30 61 views
0

如何返回空栏位的自定义消息在轨道中?铁路返回自定义空白字段错误消息

validates_presence_of :name, :description, :message => "Please fill in the required fields." 

如果两个都为空,则返回错误消息的两个实例。我只是想让它返回一次。

这可能吗?

回答

1

现在,设置人性化的名称和自定义错误信息的接受方式是使用当地人(For more reference click here

# config/locales/en.yml 
    en: 
     activerecord: 
     attributes: 
      user: 
      email: "E-mail address" 
     errors: 
      models: 
      user: 
       attributes: 
       email: 
        blank: "is required" 

现在人性化的名称和“电子邮件”属性的存在验证消息已经改变。

可以为特定模型+属性,模型,属性或全局设置验证消息。