Module: ErrorMerger

Defined in:
lib/error_merger/version.rb,
lib/error_merger/error_merger.rb

Constant Summary collapse

VERSION =
'0.1.0'

Instance Method Summary collapse

Instance Method Details

#merge(association, prefix = nil) ⇒ Object

merges an association’s Errors set into the current set eg: @user.errors.merge @account

@user.errors.merge @account, "Account ##{@account.id}: "


5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/error_merger/error_merger.rb', line 5

def merge(association, prefix=nil)
  if association.errors.respond_to? :full_message
    prefix ||= "#{association.class.model_name.human}: "
    association.errors.each do |attr, error|
      add :base, "#{prefix}#{association.errors.full_message(attr, error)}"
    end
  else
    association.errors.each do |error|
      add :base, error
    end
  end
end