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

 手机用户2502902913 发布于 2023-01-30 10:05

因此,我使用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

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

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

bundle exec rails console production

跑了 -

Geocoder.search("San Francisco, CA")

这产生了这个错误 -

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

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

Geocoder::Configuration.timeout = 15

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

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

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

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

    2023-01-30 10:09 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有