activerecord_postgis_adapter:nil:NilClass的未定义方法“点" [英] activerecord_postgis_adapter: undefined method `point' for nil:NilClass

查看:99
本文介绍了activerecord_postgis_adapter:nil:NilClass的未定义方法“点"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

90%的人确定这是我的设置错误,但是我无法做self.factory,尝试访问lonlat会给我一个异常"nil:NilClass的未定义方法'point'"

90% sure it's a setup error on my end, but I can't do self.factory and trying to access lonlat gives me an exception "undefined method `point' for nil:NilClass"

使用以下方式设置lonlat:

Set lonlat using:

mfactory = RGeo::ActiveRecord::SpatialFactoryStore.instance.factory(:geo_type => 'point')
self.lonlat = mfactory.point(long, lat)
self.save

这给了我数据库中的0101000020E610000061C3D32B65965DC03657CD7344F64040之类的值.

This gives me values like 0101000020E610000061C3D32B65965DC03657CD7344F64040 in the db.

我不能使用:

self.lonlat = "POINT(#{long},#{lat})"
self.save

问题

我需要设置模型中的特定内容吗?

Questions

Do I need to setup something specific in the model?

推荐答案

我创建了一个github问题,简明扼要,但解释更为详尽.

RGeos取决于GEOS.此错误是RGeos无法加载GEOS的结果.

RGeos depends on GEOS. This error is a result of RGeos not being able to load GEOS.

要检查是否存在此问题:

To check if this is the issue:

$ rails c
> RGeo::Geos.supported?
=> false

要检查是否已安装GEOS:

To check if you have GEOS installed:

geos-config --version

如果未安装GEOS:

brew install geos

如果已安装GEOS,请修复已安装的RGeo:

If GEOS is installed, fix your installed RGeo:

$ geos-config --prefix
/usr/local/Cellar/geos/3.5.0
$ gem install rgeo -- --with-geos-dir=/usr/local/Cellar/geos/3.5.0

现在应该已正确安装,并且您的错误已修复.您可以像上面一样检查:

Should now be installed correctly and your errors fixed. You can check as we did above:

$ rails c
> RGeo::Geos.supported?
=> true

如果这不起作用,请卸载所有版本的geos和rgeo:

If this doesn't work uninstall ALL versions of geos and rgeo:

$ brew uninstall geos
$ gem uninstall rgeo

按照上面的指示重新安装geos和rgeo.您的Gemfile中应该有gem'rgeo',并且在捆绑之后,您应该将其视为输出之一:使用本机扩展名安装rgeo 0.4.0"

Re-install geos and rgeo as instructed above. You should have gem 'rgeo' in your Gemfile and after you bundle, you should see this as one of the outputs: "Installing rgeo 0.4.0 with native extensions"

这篇关于activerecord_postgis_adapter:nil:NilClass的未定义方法“点"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆