Module: Railsstrap::FormErrorsHelper

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



5
6
7
# File 'app/helpers/railsstrap/form_errors_helper.rb', line 5

def object
  @object
end

#templateObject (readonly)

Returns the value of attribute template.



4
5
6
# File 'app/helpers/railsstrap/form_errors_helper.rb', line 4

def template
  @template
end

Instance Method Details

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



7
8
9
10
11
12
13
14
15
16
# File 'app/helpers/railsstrap/form_errors_helper.rb', line 7

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



22
23
24
# File 'app/helpers/railsstrap/form_errors_helper.rb', line 22

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

#errors_on?(attribute) ⇒ Boolean

Returns:

  • (Boolean)


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

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