相关疑难解决方法(0)

猴子修补ActiveResource ::错误

我遇到了一个已经解决的 ActiveResource 问题,并试图将它修补到我的应用程序中而没有太多运气.

我在config/initializers /中添加了一个包含以下内容的文件:

class ActiveResource::Errors < ActiveModel::Errors
    # https://github.com/rails/rails/commit/b09b2a8401c18d1efff21b3919ac280470a6eb8b
    def from_hash(messages, save_cache = false)
      clear unless save_cache

      messages.each do |(key,errors)|
        errors.each do |error|
          if @base.attributes.keys.include?(key)
            add key, error
          elsif key == 'base'
            self[:base] << error
          else
            # reporting an error on an attribute not in attributes
            # format and add themActive  to base
            self[:base] << "#{key.humanize} #{error}"
          end
        end
      end
    end

    # Grabs errors from a json response.
    def from_json(json, save_cache = false)
      decoded = ActiveSupport::JSON.decode(json) …
Run Code Online (Sandbox Code Playgroud)

monkeypatching ruby-on-rails activeresource

1
推荐指数
1
解决办法
1352
查看次数