Class: ActiveResource::Errors

Inherits:
Object
  • Object
show all
Defined in:
lib/remotable/active_resource_fixes.rb

Overview

ActiveResource expects that errors will be an array of string However, this is not what Rails Responders are inclined to return.

Instance Method Summary collapse

Instance Method Details

#from_array(array, save_cache = false) ⇒ Object

Grabs errors from an array of messages (like ActiveRecord::Validations). The second parameter directs the errors cache to be cleared (default) or not (by passing true).



65
66
67
68
69
70
71
72
73
# File 'lib/remotable/active_resource_fixes.rb', line 65

def from_array(array, save_cache=false)
  clear unless save_cache
  hash = array[0] || {}
  hash.each do |key, value|
    Array.wrap(value).each do |message|
      self[key] = message
    end
  end
end