I have a custom validator and I am trying to output an error message when it fails but have been unable to do so. Could someone please tell me if I am doing this in the correct place.
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
I had it as follows:
validates :printer_port, :presence => true, :message => "can't be blank", :if => :has_wfm_association?
But was receiving an error
Unknown validator: 'MessageValidator'
And when I tried to put the message at the end of the validator the comma seperating the has_association? turned the question mark and comma orange