Class: ActiveResource::Errors

Inherits:
ActiveModel::Errors
  • Object
show all
Defined in:
lib/active_resource/json_errors.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) from_hash(messages, save_cache = false)



5
6
7
8
9
10
11
12
13
# File 'lib/active_resource/json_errors.rb', line 5

def from_hash(messages, save_cache = false)
  clear unless save_cache

  messages.each do |key,errors|
    errors.each do |error|
      add(key, error)
    end
  end
end

- (Object) from_json(json, save_cache = false)

Grabs errors from a json response.



16
17
18
19
# File 'lib/active_resource/json_errors.rb', line 16

def from_json(json, save_cache = false)
  hash = ActiveSupport::JSON.decode(json)['errors'] || {} rescue {}
  from_hash hash, save_cache
end