我的模型中有以下代码
geocoded_by :street_address
在某些时候我会
place.geocode
如何确定是否达到了地理编码器错误限制?我没有收到任何异常,只是打印了以下消息:Google API error: over query limit.
另外,如果地理编码不是直接触发而是通过回调触发,我该怎么做?
非常感谢你!
我发现我需要使用以下命令生成地理编码器配置文件:
rails generate geocoder:config
并添加以下行:
always_raise: [Geocoder::OverQueryLimitError]
.
然后在我的代码中拯救异常:
def my_method
place.geocode
rescue Geocoder::OverQueryLimitError
puts('The geocoder limit has been reached.')
end
我还没有想出如何从回调中做到这一点。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句