我不知 Prop 体原因,但 gem 工作正常,除了它似乎不遵守配置文件这一事实。
当我使用“puts”命令测试其初始化时,它在控制台中显示该文件正在被读取。
核心问题是我想让我的地理编码器 gem 使用方法查找来确定 maxmind 或 google 的 ip 位置服务的用户位置,因为 freegeoip 只会给我错误的结果。
这是我自己创建的/config/initializers/geocoder.rb 文件:
# config/initializers/geocoder.rb
def self.options_and_defaults
[
# geocoding service timeout (secs)
[:timeout, 3],
# name of geocoding service (symbol)
[:lookup, :google],
# ISO-639 language code
[:language, :en],
# use HTTPS for lookup requests? (if supported)
[:use_https, false],
# HTTP proxy server (user:pass@host:port)
[:http_proxy, nil],
# HTTPS proxy server (user:pass@host:port)
[:https_proxy, nil],
# API key for geocoding service
[:api_key, nil],
# cache object (must respond to #[], #[]=, and #keys)
[:cache, nil],
# prefix (string) to use for all cache keys
[:cache_prefix, "geocoder:"],
# exceptions that should not be rescued by default
# (if you want to implement custom error handling);
# supports SocketError and TimeoutError
[:always_raise, []]
]
end
我还将此代码与我的 google api 代码和 google 一起使用进行查找,并与 maxmind 一起使用...两者都返回我实际上地理编码器仍然使用 freegeoip
我在 Controller 上实现了一个“puts”条目:
puts 'oioioi'
puts request.ip
puts Geocoder.search(request.ip).first
puts request.location
这样我就可以在控制台输出上检测到它。
我得到了:
oioioi
127.0.0.1
#<Geocoder::Result::Freegeoip:0x007fbe846eb258>
#<Geocoder::Result::Freegeoip:0x007fbe847232e8>
我知道我使用本地 IP,但我已经在部署上进行了测试,事实是查找仍在使用 Freegeoip 作为查找服务器。
希望有人能帮助我...提前致谢。
最佳答案
我没有使用正确的配置。我需要设置 :ip_lookup 才能使其正常工作。
关于ruby-on-rails - Rails Gem Geocoder Lookup方法不遵守/config/initializers/geocoder.rb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16578762/