Module: Railsstrap::FormErrorsHelper
- Includes:
- ActionView::Helpers::FormTagHelper
- Defined in:
- app/helpers/railsstrap/form_errors_helper.rb
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
- #error_span(attribute, options = {}) ⇒ Object
- #errors_for(attribute) ⇒ Object
- #errors_on?(attribute) ⇒ Boolean
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
5 6 7 |
# File 'app/helpers/railsstrap/form_errors_helper.rb', line 5 def object @object end |
#template ⇒ Object (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, = {}) [:span_class] ||= 'help-block' [:error_class] ||= 'has-error' if errors_on?(attribute) @template.content_tag( :div, :class => [:error_class] ) do content_tag( :span, errors_for(attribute), :class => [: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
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 |