Class: NForm::ValidationError

Inherits:
Error
  • Object
show all
Defined in:
lib/nform/form.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(errors = {}) ⇒ ValidationError

Returns a new instance of ValidationError.



30
31
32
# File 'lib/nform/form.rb', line 30

def initialize(errors={})
  @errors = errors
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



29
30
31
# File 'lib/nform/form.rb', line 29

def errors
  @errors
end

Instance Method Details

#error_messagesObject



38
39
40
41
42
# File 'lib/nform/form.rb', line 38

def error_messages
  if errors.any?
    errors.map{|k,v| "#{k.to_s.humanize}: #{v}"}.join("\n")
  end
end

#messageObject



34
35
36
# File 'lib/nform/form.rb', line 34

def message
  "\nPlease correct the following errors:\n#{error_messages}"
end