为什么我得到一个零对象而不是一点点的短链接?

我基于这个例子使用了一个简单的简单实现:http://www.appelsiini.net/2010/using-bitly-with-httparty 我把这个文件放在lib文件夹中(bitly.rb)
require 'rubygems'
require 'httparty'
class Bitly
  include HTTParty
  base_uri "api.bit.ly"

  @@login   = "goldhat"
  @@api_key = "R_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

  def self.shorten(url)
    response = get("/v3/shorten?login=#{@@login}&apiKey=#{@@api_key}&longUrl=#{url}")
    response["data"]["url"]
  end
end
由于某种原因,我得到一个零对象。好像有点甚至没有回应任何数据。我在我的控制台和我的应用程序中测试了它并得到了同样的错误:
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]
        from c:/goldhat_production/lib/bitly.rb:9:in `shorten'
        from (irb):1
有任何想法吗?     
已邀请:
DIY的替代品 - 你可以在这里找到经过充分测试的Ruby宝石。     
问题不在于Bitly代码,而在于你将它放在Rails 3应用程序的lib /目录中。要获得lib / load,需要在
config/application.rb
中进行以下操作:
config.autoload_paths += %W(#{config.root}/lib)
    

要回复问题请先登录注册