Failed to recognize type of 'location'. It will be treated as String

不打扰是莪最后的温柔 提交于 2019-12-10 19:52:48

问题


I'm trying to use the gem activerecord-postgis-adapter and when i try to execute this code :

require 'active-record' 
require 'pg'
require 'active record-postgis-adapter'

class Place < ActiveRecord::Base
   record = Place.find(1)
   line = record.location
   puts line.srid
end

srid is a method of activerecord-postgis-adapter and here i'm trying to display the srid of my geographical column (location) but the console keeps telling me Failed to recognize type of 'location'. It will be treated as String..


回答1:


Probably found a solution to my problem, i used postgresql as the adapter when connecting to the database, i changed to postgis and now it works.




回答2:


1)Your example has a space in "active record".

Use require 'activerecord-postgis-adapter'.

2) As mentioned in other answer: change postgresql for postgis:

In project_name/config/database.yml, change the adapter:

 default: &default
  adapter: postgresql

Becomes

 default: &default
  adapter: postgis

3) Make sure you have the postgis extension enabled psql -d your_project_name_development -tAc "SELECT 1 from pg_extension where extname='postgis'" | grep -q 1 || \ psql -d your_project_name_development --command="CREATE EXTENSION postgis"

Also, in my project, I had to reimport the data.

Note: you might also need require 'rgeo-activerecord' if you're using the RGeo gem.



来源:https://stackoverflow.com/questions/37163196/failed-to-recognize-type-of-location-it-will-be-treated-as-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!