30

我收到这个错误

未知验证器:'MessageValidator'

我不知道为什么我会得到那个。
我的代码有什么问题?

validates :title,   
    :presence => true,   
    :uniqueness => true,   
    :length => { :maximum => 100 },
    :message => "Must be input and has to be less than 100 characters, and unique."
4

2 回答 2

61

尝试:

validates :title, 
          :presence => {:message => "Title can't be blank." },
          :uniqueness => {:message => "Title already exists."},
          :length => { :maximum => 100, :message => "Must be less than 100 characters"}
于 2013-01-22T05:52:12.140 回答
7

我假设您希望消息在长度验证失败时出现。您应该在该哈希中包含消息,例如:

validates :title,   
    :presence => true,   
    :uniqueness => true,   
    :length => { :maximum => 100, :message => "Must be less than 100 characters"}
于 2013-01-22T04:59:43.330 回答