json_errors.rb 502 B

123456789101112131415161718192021
  1. require 'active_resource/base'
  2. module ActiveResource
  3. class Errors < ActiveModel::Errors
  4. def from_hash(messages, save_cache = false)
  5. clear unless save_cache
  6. messages.each do |key,errors|
  7. errors.each do |error|
  8. add(key, error)
  9. end
  10. end
  11. end
  12. # Grabs errors from a json response.
  13. def from_json(json, save_cache = false)
  14. hash = ActiveSupport::JSON.decode(json)['errors'] || {} rescue {}
  15. from_hash hash, save_cache
  16. end
  17. end
  18. end