Module: Formtastic::Inputs::Base::Errors

Included in:
Formtastic::Inputs::Base
Defined in:
lib/formtastic/inputs/base/errors.rb

Instance Method Summary collapse

Instance Method Details

#error_first_htmlObject



25
26
27
28
# File 'lib/formtastic/inputs/base/errors.rb', line 25

def error_first_html
  error_class = builder.default_inline_error_class
  template.(:p, errors.first.untaint.html_safe, :class => error_class)
end

#error_htmlObject



7
8
9
# File 'lib/formtastic/inputs/base/errors.rb', line 7

def error_html
  errors? ? send(:"error_#{builder.inline_errors}_html") : +""
end

#error_keysObject



48
49
50
51
52
53
# File 'lib/formtastic/inputs/base/errors.rb', line 48

def error_keys
  keys = [method.to_sym]
  keys << builder..map{|suffix| "#{method}_#{suffix}".to_sym} if file?
  keys << association_primary_key if belongs_to? || has_many?
  keys.flatten.compact.uniq
end

#error_list_htmlObject



16
17
18
19
20
21
22
23
# File 'lib/formtastic/inputs/base/errors.rb', line 16

def error_list_html
  error_class = builder.default_error_list_class
  list_elements = []
  errors.each do |error|
    list_elements << template.(:li, error.html_safe)
  end
  template.(:ul, list_elements.join("\n").html_safe, :class => error_class)
end

#error_none_htmlObject



30
31
32
# File 'lib/formtastic/inputs/base/errors.rb', line 30

def error_none_html
  +""
end

#error_sentence_htmlObject



11
12
13
14
# File 'lib/formtastic/inputs/base/errors.rb', line 11

def error_sentence_html
  error_class = builder.default_inline_error_class
  template.(:p, errors.to_sentence, :class => error_class)
end

#errorsObject



38
39
40
41
42
43
44
45
46
# File 'lib/formtastic/inputs/base/errors.rb', line 38

def errors
  errors = []
  if object && object.respond_to?(:errors)
    error_keys.each do |key| 
      errors << object.errors[key] unless object.errors[key].blank?
    end
  end
  errors.flatten.compact.uniq
end

#errors?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/formtastic/inputs/base/errors.rb', line 34

def errors?
  !errors.blank?
end