Module: ActionView::Helpers::ErrorMessageForMobile

Defined in:
lib/action_view/helpers/error_message_for_mobile.rb

Defined Under Namespace

Modules: FormBuilderMethods

Instance Method Summary collapse

Instance Method Details

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



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/action_view/helpers/error_message_for_mobile.rb', line 10

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

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

  object = convert_to_model(object)

  if (obj = (object.respond_to?(:errors) ? object : instance_variable_get("@#{object}"))) &&
    (errors = obj.errors[method]).presence
    html = ("span",
             (options[:prepend_text].html_safe << errors.first).safe_concat(options[:append_text]),
             :style => "color:#{options[:color]};"
           )
    html << '<br />'
  else
    ''
  end
end