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

- (Object) error_first_html



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

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

- (Object) error_html



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

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

- (Object) error_keys



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

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

- (Object) error_list_html



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

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

- (Object) error_none_html



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

def error_none_html
  ""
end

- (Object) error_sentence_html



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

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

- (Object) errors



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

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

- (Boolean) errors?

Returns:

  • (Boolean)


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

def errors?
  !errors.blank?
end