我不知道确切原因,但 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
我在我的控制器上实现了一个“puts”条目:
puts 'oioioi'
puts request.ip
puts Geocoder.search(request.ip).first
puts request.location
so i could detect it on the console output.
I got:
oioioi
127.0.0.1
#<Geocoder::Result::Freegeoip:0x007fbe846eb258>
#<Geocoder::Result::Freegeoip:0x007fbe847232e8>
I know that im using a local IP but i already tested on deplyoment and the fact is that the lookup is still using Freegeoip as lookup server.
Hope anybody could help me... Thanks in advance.