Sha256: 5534f49d949b4a22bdad4e2ecd5c720558bbfd4b8edb3302a546166b704305b5

Contents?: true

Size: 562 Bytes

Versions: 2

Compression:

Stored size: 562 Bytes

Contents

require "active_resource/validations"

module ActiveResource
  class Errors < ActiveModel::Errors
    def from_json(json, save_cache = false)
      decoded = ActiveSupport::JSON.decode(json) || {} rescue {}
      from_hash decoded, save_cache
    end

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

      messages.each do |(key,errors)|
        Array(errors).each do |error|
          if key == 'base'
            self[:base] << error
          else
            add key, error
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mite-rb-0.5.4 lib/mite/activeresource_patch.rb
mite-rb-0.5.3 lib/mite/activeresource_patch.rb