Geocoder Gem无法在生产环境中工作

Noa*_*vis 3 ruby ruby-on-rails production-environment rails-geocoder

因此,我使用Geocoder根据用户在提交表单时提供的地址提取纬度和经度坐标.我这样做是为了让我可以使用Google Maps API绘制标记.这在开发中非常有效 - 零问题.然而,当我推向生产时,Geocoder不会生成纬度和经度.我检查了我的生产日志,没有错误.我还检查确保gem不仅仅是为了开发安装而且我已经在我的生产机器上重新启动了unicorn和nginx.关于可能发生什么的任何想法?

这是我正在执行此任务的模型的模型代码 -

class Order < ActiveRecord::Base

  attr_accessible :city, :customer_email, :customer_id, :delivery_date, :delivery_time, :street, :zipcode, :coupon, :total, :name, :items_with_day, :user_id, :shopping_cart_id, :extras, :latitude, :longitude, :location_name, :phone, :suite, :state

  belongs_to :user

  validates :name, :presence => true
  validates :street, :presence => true
  validates :city, :presence => true
  validates :zipcode, :presence => true

  def address
    [street, city, state, "United States"].compact.join(', ')
  end

  geocoded_by :address
  after_validation :geocode

end
Run Code Online (Sandbox Code Playgroud)

============更新=============

所以在提出建议后,我在生产机器上打开了rails控制台 -

bundle exec rails console production
Run Code Online (Sandbox Code Playgroud)

跑了 -

Geocoder.search("San Francisco, CA")
Run Code Online (Sandbox Code Playgroud)

这产生了这个错误 -

Geocoding API not responding fast enough (use Geocoder.configure(:timeout => ...) to set limit).
=> []
Run Code Online (Sandbox Code Playgroud)

话虽如此,在我的config/initilizers/geocoder.rb文件中,我有 -

Geocoder::Configuration.timeout = 15
Run Code Online (Sandbox Code Playgroud)

设置的适当超时限制是多少?我需要坐标,但也不想让它永远运行......

===========更新=============

我找到了这个相关的问题,虽然我更喜欢运行这个任务服务器端,而不是在客户端.

小智 6

您的初始化程序可能未在生产环境中加载.尝试运行控制台命令(bundle exec rails console production)并Geocoder::Configuration.timeout = 15在控制台中运行,然后再次尝试测试命令.