[DEPRECATION]不推荐使用MultiJson.decode

时间:2012-04-17 11:30:05

标签: ruby-on-rails ruby-on-rails-3.1

我有一个简单的类,当用户请求服务器时,我想将其作为JSON输出。

class GeoName

include ActiveModel::Validations
include ActiveModel::Serialization

validates :country_name, :presence => true, :length => {:minimum => 1}
validates :country_code, :presence => true, :length => {:minimum => 1}
validates :province, :presence => true, :length => {:minimum => 1}
validates :district, :presence => true, :length => {:minimum => 1}
validates :zip_code, :presence => true, :length => {:minimum => 1}
validates :city, :presence => true, :length => {:minimum => 1}
validates :street, :presence => true, :length => {:minimum => 1}

attr_accessor :country_name, :country_code, :province, :district, :zip_code, :city, :street


def attributes
 @attributes ||= {'country_name' => country_name, 'country_code' => country_code, 'province' => province,'district' => district,'zip_code' => zip_code,'city' => city, 'street' => street}
end


end

在控制器中,我执行以下操作:

def index
    geoname = GeoName.new 
    geoname.street = "blablabla"
    geoname.city = "blablabla" 
    render :json => geoname.to_json
  end

在routes.rb

controller :testcontroller do
    match 'testme', :to => :index
  end

当我请求url localhost:3000 / testme时,我收到一个有效的JSON响应。但是在控制台中有弃用警告

rvm/gems/ruby-1.9.3-p125@geo/gems/activesupport-3.1.0/lib/active_support/json/decoding.rb:12:in `decode': [DEPRECATION] MultiJson.decode is deprecated and will be removed in the next major version. Use MultiJson.load instead.

Ruby版本1.9.3-p125和rails - 3.1.0。

1 个答案:

答案 0 :(得分:0)

快速谷歌会显示这是来自MultiJSON的警告,该警告应该在另一个版本中消失(当不推荐的代码及其消息从gem代码中删除时)。基本上这是对在其代码中使用MultiJSON.decode的开发人员的警告。如果您未在代码中使用MultiJSON.decode,请忽略它。

只要更新了从属宝石并将更新的宝石捆绑到您的项目中,该消息就可能消失。