【发布时间】:2012-05-07 07:19:02
【问题描述】:
我有一个自定义验证器,我尝试在它失败但无法输出时输出错误消息。如果我在正确的地方这样做,有人可以告诉我。
class User < ActiveRecord::Base
self.table_name = "user"
attr_accessible :name, :ip, :printer_port, :scanner_port
validates :name, :presence => true,
:length => { :maximum => 75 },
:uniqueness => true
validates :ip, :length => { :maximum => 75 },
:allow_nil => true
validates :printer_port, :presence => true, :if => :has_association?
validates :scanner_port, :presence => true, :if => :has_association?
def has_association?
ip != nil
end
end
我是这样的:
validates :printer_port, :presence => true, :message => "can't be blank", :if => :has_wfm_association?
但是收到一个错误
Unknown validator: 'MessageValidator'
当我试图将消息放在验证器的末尾时,逗号分隔 has_association?把问号和逗号变成橙色
【问题讨论】:
标签: ruby-on-rails-3 rspec2 customvalidator custom-errors