Class: Reform::Form::Errors

Inherits:
ActiveModel::Errors
  • Object
show all
Defined in:
lib/reform/form.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 = nil) ⇒ Object

def each

messages.each_key do |attribute|
  self[attribute].each { |error| yield attribute, Array.wrap(error) }
end

end



250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/reform/form.rb', line 250

def merge!(errors, prefix=nil)
  # TODO: merge into AM.
  errors.messages.each do |field, msgs|
    field = "#{prefix}.#{field}" if prefix

    msgs = [msgs] if Reform.rails3_0? # DISCUSS: fix in #each?

    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

#messagesObject



239
240
241
242
# File 'lib/reform/form.rb', line 239

def messages
  return super unless Reform.rails3_0?
  self
end