Class: Reform::Contract::Errors

Inherits:
ActiveModel::Errors
  • Object
show all
Defined in:
lib/reform/form/active_model/errors.rb

Overview

The Errors class is planned to replace AM::Errors. It provides proper nested error messages.

Instance Method Summary collapse

Instance Method Details

#merge!(errors, prefix) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/reform/form/active_model/errors.rb', line 3

def merge!(errors, prefix)
  errors.messages.each do |field, msgs|
    unless field.to_sym == :base
      field = (prefix+[field]).join(".").to_sym # TODO: why is that a symbol in Rails?
    end

    msgs.each do |msg|
      next if messages[field] and messages[field].include?(msg)
      add(field, msg)
    end # Forms now contains a plain errors hash. the errors for each item are still available in item.errors.
  end
end

#to_sObject



20
21
22
# File 'lib/reform/form/active_model/errors.rb', line 20

def to_s
  messages.inspect
end

#valid?Boolean

TODO: test me in unit test.

Returns:

  • (Boolean)


16
17
18
# File 'lib/reform/form/active_model/errors.rb', line 16

def valid? # TODO: test me in unit test.
  empty?
end