【发布时间】:2014-11-22 06:05:24
【问题描述】:
过去一周,我注意到在我使用 Geocoder gem 请求位置的页面上,我的 heroku 应用经常显示
Application Error
An error occurred in the application and your page could not be served. Please try again in a few moments.
If you are the application owner, check your logs for details.
日志显示
Geocoding API not responding fast enough (use Geocoder.configure(:timeout => ...)
我以前从未注意到这个问题,但也许它一直存在,只是我直到最近才经常访问有问题的页面。超时与访问页面的发生似乎是随机的。
所以我加了
Geocoder.configure(
:timeout => 40
)
到我的 config/initializers/geocoder.rb。我认为这导致更频繁地访问页面,但加载通常需要一段时间。
我正在这些页面上实施默认邮政编码,这样我就不会收到应用程序错误,但从长远来看这并不理想。
我试过了
if params[:search].present?
@events = Event.near(params[:search], params[:dist], order: 'distance')
elsif user_signed_in? && current_user.address
@events = Event.near([current_user.latitude, current_user.longitude], 25, order: 'distance')
elsif request.location
@events = Event.near([request.location.latitude, request.location.longitude], 25, order: 'distance')
else
@events = Event.near(20016, 100, order: 'distance')
希望在 request.location 超时时获得默认邮政编码 20016,但我仍然收到应用程序错误。
还有其他建议吗?
【问题讨论】:
标签: ruby-on-rails heroku rails-geocoder