class ActiveUtils::Validateable::Errors
This hash keeps the errors of the object
def add(field, error)
def add(field, error) self[field] << error end
def add_to_base(error)
def add_to_base(error) add(:base, error) end
def count
def count size end
def each_full
def each_full full_messages.each { |msg| yield msg } end
def empty?
def empty? all? { |k, v| v && v.empty? } end
def full_messages
def full_messages result = [] self.each do |key, messages| next if messages.blank? if key == 'base' result << "#{messages.first}" else result << "#{key.to_s.humanize} #{messages.first}" end end result end
def initialize(base)
def initialize(base) super() { |h, k| h[k] = [] ; h[k] } @base = base end
def on(field)
if more than one error is available we will only return the first. If no error is available
returns a specific fields error message.
def on(field) self[field].to_a.first end