2012-04-17 345 views
3

我有一個簡單的類,當用戶請求服務器時,我想以JSON形式輸出。[棄權] MultiJson.decode已棄用

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本地主機:3000/TESTME我接收到有效的JSON響應。然而,在控制檯上存在棄用現象

rvm/gems/[email protected]/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。

回答

0

快速谷歌會顯示這是從MultiJSON應該在進一步的版本(當不再使用的代碼和它的消息從寶石代碼中刪除)的警告。基本上這是對開發者在他們的代碼中使用MultiJSON.decode的警告。如果您在代碼中不使用MultiJSON.decode,請忽略它。

只要更新了依賴項並將更新後的項捆綁到項目中,則消息可能會消失。