Module: GenericFormFor::Inputs::Base::ErrorMessage

Included in:
GenericFormFor::Inputs::Base
Defined in:
lib/generic_form_for/inputs/base/error_message.rb

Instance Method Summary collapse

Instance Method Details

#error_html(config_options = {}) ⇒ Object



6
7
8
# File 'lib/generic_form_for/inputs/base/error_message.rb', line 6

def error_html(config_options={})
  template.concat(render_error? ? template.(:span, errors.join(", "), error_html_options(config_options)) : "")
end

#error_html_options(config_options = {}) ⇒ Object



10
11
12
13
14
# File 'lib/generic_form_for/inputs/base/error_message.rb', line 10

def error_html_options(config_options={})
  opts = (options[:error_html] || {}).dup
  opts[:class] = ["error", *opts[:class], *config_options[:class]].compact.join(' ').strip   
  config_options.merge(opts)
end

#errorsObject



16
17
18
# File 'lib/generic_form_for/inputs/base/error_message.rb', line 16

def errors
  @errors ||= object.respond_to?(:errors) ? object.errors[method.to_s] : []
end

#errors?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/generic_form_for/inputs/base/error_message.rb', line 20

def errors?
  !errors.empty?
end

#render_error?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/generic_form_for/inputs/base/error_message.rb', line 24

def render_error?
  errors?
end