Module: ActionView::Helpers::ActiveRecordHelper

Defined in:
lib/plugins/monkey_patches/lib/monkey_patches.rb

Overview

So we get error messages wrapped in a span instead of a div which will tend to mess up forms

Instance Method Summary collapse

Instance Method Details

#error_message_on(object, method, *args) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/plugins/monkey_patches/lib/monkey_patches.rb', line 9

def error_message_on(object, method, *args)
  options = args.extract_options!
  unless args.empty?
    ActiveSupport::Deprecation.warn('error_message_on takes an option hash instead of separate ' +
      'prepend_text, append_text, and css_class arguments', caller)

    options[:prepend_text] = args[0] || ''
    options[:append_text] = args[1] || ''
    options[:css_class] = args[2] || 'formError'
  end
  options.reverse_merge!(:prepend_text => '', :append_text => '', :css_class => 'formError')

  if (obj = (object.respond_to?(:errors) ? object : instance_variable_get("@#{object}"))) &&
    (errors = obj.errors.on(method))
    ("span",
      "#{options[:prepend_text]}#{errors.is_a?(Array) ? errors.first : errors}#{options[:append_text]}",
      :class => options[:css_class]
    )
  else
    ''
  end
end