Module: FormErrorsHelper

Includes:
ActionView::Helpers::FormTagHelper
Defined in:
app/helpers/form_errors_helper.rb

Instance Method Summary collapse

Instance Method Details

#error_span(attribute, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'app/helpers/form_errors_helper.rb', line 4

def error_span(attribute, options = {})
  options[:span_class] ||= 'help-block'
  options[:error_class] ||= 'has-error'

  if errors_on?(attribute)
    @template.( :div, :class => options[:error_class] )  do
      ( :span, errors_for(attribute), :class => options[:span_class] )
    end
  end
end

#errors_for(attribute) ⇒ Object



19
20
21
# File 'app/helpers/form_errors_helper.rb', line 19

def errors_for(attribute)
  object.errors[attribute].try(:join, ', ') || object.errors[attribute].try(:to_s)
end

#errors_on?(attribute) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'app/helpers/form_errors_helper.rb', line 15

def errors_on?(attribute)
  object.errors[attribute].present? if object.respond_to?(:errors)
end