Module: FormErrorsHelper

Defined in:
app/helpers/form_errors_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



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

def object
  @object
end

#templateObject (readonly)

Returns the value of attribute template.



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

def template
  @template
end

Instance Method Details

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



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

def error_span(attribute, options = {})
  options[:class] ||= 'help-inline'

  template.(
    :span, self.errors_for(attribute),
    :class => options[:class]
  ) if self.errors_on?(attribute)
end

#errors_for(attribute) ⇒ Object



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

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

#errors_on?(attribute) ⇒ Boolean

Returns:

  • (Boolean)


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

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