【问题标题】:Failed to recognize type of 'location'. It will be treated as String无法识别“位置”的类型。它将被视为字符串
【发布时间】:2016-05-11 12:49:14
【问题描述】:
我正在尝试使用 gem activerecord-postgis-adapter 并且当我尝试执行此代码时:
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 是activerecord-postgis-adapter 的一种方法,在这里我试图显示我的地理列(位置)的srid,但控制台一直告诉我@987654324 @。
【问题讨论】:
标签:
ruby-on-rails
database
postgresql
rubygems
postgis
【解决方案1】:
可能找到了解决我的问题的方法,我在连接数据库时使用 postgresql 作为适配器,我更改为 postgis 现在它可以工作了。
【解决方案2】:
1)您的示例在“活动记录”中有一个空格。
使用require 'activerecord-postgis-adapter'。
2) 如其他答案所述:将 postgresql 更改为 postgis:
在project_name/config/database.yml中,更改适配器:
default: &default
adapter: postgresql
变成
default: &default
adapter: postgis
3) 确保您启用了 postgis 扩展
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"
另外,在我的项目中,我必须重新导入数据。
注意:如果您使用 RGeo gem,您可能还需要 require 'rgeo-activerecord'。