gpt4 book ai didi

ruby-on-rails - Rails Gem Geocoder Lookup 方法不遵守/config/initializers/geocoder.rb

转载 作者:行者123 更新时间:2023-12-04 04:57:33 26 4
gpt4 key购买 nike

我不知道为什么,但 gem 工作正常,除了它似乎不遵守配置文件的事实。

当我使用“puts”命令测试它的初始化时,它会在控制台中显示正在读取文件。

中心问题是我想让我的地理编码器 gem 使用方法查找来确定用户位置与 maxmind 或谷歌的 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com