rubysl/net/http/http.rb 上 nil:NilClass 上的未定义方法 `to_sym' 由 Rails Geocoder 引起

undefined method `to_sym' on nil:NilClass on rubysl/net/http/http.rb caused by Rails Geocoder

所以我在 Rails 上的 Ruby 网站上工作,该网站使用 Geocoder gem.

这是我的实现:

def User < ActiveRecord::Base    
    before_save :geocode
    geocoded_by :address do |usr, geocode_results|
    if geo = geocode_results.first
       usr.latitude  = geo.latitude
       usr.longitude = geo.longitude
       usr.geocode_address = geo.address
    else
      usr.latitude  = nil
      usr.longitude = nil
      usr.geocode_address = nil
    end
end

并且最初在生产中它可以工作...但是在 2-3 天后,我会在任何调用 @user.save

的控制器操作上收到一条错误消息说 undefined method to_sym on nil:NilClass.

我进一步调查,这里是堆栈跟踪:

Stacktrace (most recent call first):   
kernel/delta/kernel.rb:78:in `to_sym (method_missing)'
rubysl/net/http/http.rb:576:in `start'
   key = .to_sym
kernel/common/enumerable.rb:217:in `grep'
kernel/bootstrap/array.rb:76:in `each'
kernel/common/enumerable.rb:213:in `grep'
rubysl/net/http/http.rb:575:in `start'
    http.methods.grep(/\A(\w+)=\z/) do |meth|
geocoder/lookups/base.rb:268:in `make_api_request'
    http_client.start(uri.host, uri.port, use_ssl: use_ssl?) do |client|
rubysl/timeout/timeout.rb:149:in `timeout'
    yield sec
rubysl/timeout/timeout.rb:168:in `timeout'
     Timeout.timeout(n, e, &block)
geocoder/lookups/base.rb:266:in `make_api_request'
    timeout(configuration.timeout) do
geocoder/lookups/base.rb:218:in `fetch_raw_data'
    response = make_api_request(query)
geocoder/lookups/base.rb:169:in `fetch_data'
    parse_raw_data fetch_raw_data(query)
geocoder/lookups/google.rb:28:in `results'
    return [] unless doc = fetch_data(query)
geocoder/lookups/base.rb:47:in `search'
    results(query).map{ |r|
geocoder/query.rb:11:in `execute'
    lookup.search(text, options)
geocoder.rb:21:in `search'
    query.blank? ? [] : query.execute
geocoder/stores/base.rb:111:in `do_lookup' 
    results = Geocoder.search(query, query_options)
geocoder/stores/active_record.rb:259:in `geocode'
    do_lookup(false) do |o,rs|   active_support/callbacks.rb:424:in `make_lambda'
    lambda { |target, _, &blk| target.send filter, &blk }

事实证明 thisto_sym for nil:NilClass 错误的罪魁祸首 - 似乎 grep 没有找到任何东西?

Net:HTTP 正在被 Rails Geocoder here 调用。

我怀疑是 rbx-2.2.1 的问题,所以我会尝试切换到 ruby-2.2.1,看看它是否会在接下来的几天内发生。有人遇到过这种情况吗?

编辑:如果我重新启动 rails 服务器线程,问题就会消失,但会在 ~1-2 天后恢复

编辑:这是导致问题的 user_controller

respond_to do |format| #line 169
    @id = @user.id
    @user.update(user_params) #line 171
    if params[:user][:redirect_to_index].present? or @user.chef?
        format.html { redirect_to root_path }
        format.json { render :show, status: :ok, location: @user }
    else
        format.html { redirect_to @user }
        format.json { render :show, status: :ok, location: @user }
    end
end

我从 rbx-2.2.1 切换到 ruby-2.2.1 解决了这个问题。这似乎是由地理编码器和 rbx-2.2.1 之间的一些错误引起的(我认为)。