问题
Problem
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"
I can
Set lonlat using:
mfactory = RGeo::ActiveRecord::SpatialFactoryStore.instance.factory(:geo_type => 'point')
self.lonlat = mfactory.point(long, lat)
self.save
This gives me values like 0101000020E610000061C3D32B65965DC03657CD7344F64040
in the db.
I can't use:
self.lonlat = "POINT(#{long},#{lat})"
self.save
Questions
Do I need to setup something specific in the model?
回答1:
I created a github issue with a less consise but more detailed explaination.
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
To check if you have GEOS installed:
geos-config --version
If GEOS isn't installed:
brew install geos
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
If this doesn't work uninstall ALL versions of geos and rgeo:
$ brew uninstall geos
$ gem uninstall rgeo
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"
来源:https://stackoverflow.com/questions/31170055/activerecord-postgis-adapter-undefined-method-point-for-nilnilclass