Module: JqueryUiForm::Helpers::ErrorHelper

Included in:
FormBuilder
Defined in:
lib/jquery_ui_form/helpers/error_helper.rb

Instance Method Summary collapse

Instance Method Details

#error_message_on(method) ⇒ Object



9
10
11
# File 'lib/jquery_ui_form/helpers/error_helper.rb', line 9

def error_message_on(method)
  @object.errors[method.to_sym].join(" #{use_i18n ? I18n.t('and') : 'and'} ")
end

#error_messages_on_baseObject



13
14
15
# File 'lib/jquery_ui_form/helpers/error_helper.rb', line 13

def error_messages_on_base
  @object.errors[:base]
end

#has_errors?(method) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/jquery_ui_form/helpers/error_helper.rb', line 5

def has_errors?(method)
  @object && @object.respond_to?(:errors) && !@object.errors[method.to_sym].blank?
end

#inline_error(method) ⇒ Object



17
18
19
20
# File 'lib/jquery_ui_form/helpers/error_helper.rb', line 17

def inline_error(method)
  return "" unless has_errors?(method)
  template.(:div, error_message_on(method), :class => "ui-input-error-message")
end

#model_errors(errors = []) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/jquery_ui_form/helpers/error_helper.rb', line 22

def model_errors(errors=[])
  errors = error_messages_on_base.to_a + errors.to_a
  return "" if errors.empty?
  template.(:div, :class => "ui-base-error-messages") do
    errors.each do |message|
      template.concat(
        template.(:p) do
          template.concat(template.(:span, "", :class => "ui-icon ui-icon-alert"))
          template.concat(template.(:strong, message))
        end
      )
    end
  end
end