Module: CombinedErrors::Model

Defined in:
lib/combined_errors.rb

Instance Method Summary collapse

Instance Method Details

#combine_errors(new_method, *methods_to_combine) ⇒ Object



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

def combine_errors new_method, *methods_to_combine
  define_method new_method do
    methods_to_combine.flatten.each do |m|
      if errors[m].any?
        title = m.to_s.respond_to?(:titleize) ? m.titleize : m.capitalize
        errors[m].each do |error|
          errors.add(new_method, "#{title} #{error}")
        end
      end
    end
    nil
  end
end