Module: FatFreeCRM::ActiveModel::Errors

Defined in:
lib/fat_free_crm/errors.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Override ActiveModel::Errors#each so we could display validation errors as is without rendering the attribute name. Simply place a caret as the first character of the error message.

This feature was handled by ‘advanced_errors’ plugin in Rails 2.x version of Fat Free CRM.




18
19
20
21
22
# File 'lib/fat_free_crm/errors.rb', line 18

def self.included(base)
  base.class_eval do
    alias_method :each, :each_with_explicit_error
  end
end

Instance Method Details

#each_with_explicit_errorObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fat_free_crm/errors.rb', line 24

def each_with_explicit_error
  keys.each do |attribute|
    self[attribute].each do |error|
      if error.start_with?('^')
        yield :base, error[1..-1]   # Drop the attribute.
      else
        yield attribute, error      # This is default Rails3 behavior.
      end
    end
  end
end