我们在Ruby on Rails上使用Postgis适配器,我们正在尝试在Heroku上使用Puma来实现我们的生产环境。我们的测试在开发系统上完美无缺。此外,服务器在每个生产服务器上都能完美运行,但是Heroku,但是一旦我们在Heroku + Puma(或Unicron)上运行它,我们就会遇到异常。
作为旁注,在Heroku上使用Webrick进行部署时,应用程序可以顺利运行。
当使用puma(以及后来的尝试,unicorn)作为默认的Web服务器时,一切顺利但只有一件事:
我使用RGeo gem来跟踪一些蜂巢位置。切换到Puma(Unicorn)时,在我的Javascript视图中调用@hive.current_location.lon
和@hive.current_location.lat
会引发错误:
ActionView::Template::Error (undefined method 'lon' and 'lat' for #<RGeo::Cartesian::PointImpl:0x007f700846c970>)
与此同时,我尝试通过heroku run rails console
有趣的是,在Heroku控制台上获取lat和long值会返回正确的值。似乎问题是由美洲狮和独角兽造成的。
有什么建议吗?
答案 0 :(得分:1)
最后我找到了解决方案。阅读这篇文章。
进一步详情:
基本上,在我的蜂巢模型中,我使用:
set_rgeo_factory_for_column(:current_location,
RGeo::Geographic.spherical_factory(:srid => 4326))
然后在我的位置创建者中,我有以下代码:
require_relative "./coordinate_builder"
require 'rgeo'
class LocationCreator
DEFAULT = "default"
def self.create(lat_lng)
return nil if lat_lng == DEFAULT
lng, lat = CoordinateBuilder.parse(lat_lng)
geographic_factory = RGeo::Geographic.spherical_factory
geographic_factory.point(lng, lat)
end
end
稍后在视图中,我使用以下代码来获取点的纬度和经度,以便创建Google地图标记并将其固定在地图上:
<% if @hive.current_location.present? %>
var myLatlng = new google.maps.LatLng(<%= @hive.current_location.latitude %>, <%=@hive.current_location.longitude %>);
var mapOptions = {
zoom: 16,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
<% end %>
问题:显然是Rgeo::Geographic::SphericalPointImpl
falls back to RGeo::Cartesian::PointImpl
in my Javascript code.
解决方法:我将我的javascript来电从@hive.current_location.lat
更改为@hive.current_location.y
。同样对于纬度,我做了同样的事情:@hive.current_location.lon
到@hive.current_location.x
。
这解决了我的问题。