Class: DataMapper::Validations::ValidationErrors

Inherits:
Object
  • Object
show all
Defined in:
lib/devise/orm/data_mapper/validations/dm-validations.rb

Overview

Monkey-patch ValidationErrors to support generation of error message from a Symbol. This does not translate, consistent with normal DataMapper operation. Set DataMapper::Validate::ValidationErrors.default_error_messages if alternate messages are needed (after devise has been initialized).

Instance Method Summary collapse

Instance Method Details

#add(field_name, message = nil, active_record_options = {}) ⇒ Object

If the message is a Symbol, allow default_error_message to generate the message, including translation.



14
15
16
17
18
19
# File 'lib/devise/orm/data_mapper/validations/dm-validations.rb', line 14

def add(field_name, message = nil, active_record_options = {})
  if message.kind_of?(Symbol)
    message = get_message(field_name, message, active_record_options)
  end
  original_add(field_name, message) unless errors[field_name].include?(message)
end

#original_addObject



10
# File 'lib/devise/orm/data_mapper/validations/dm-validations.rb', line 10

alias_method :original_add, :add

#to_xml(options = {}) ⇒ Object

Some devise controller actions expect resource#errors to respond to #to_xml. Otherwise, we get a Missing template error



23
24
25
# File 'lib/devise/orm/data_mapper/validations/dm-validations.rb', line 23

def to_xml(options = {})
  @errors.to_hash.to_xml(options.merge(:root => 'errors'))
end