我尝试使用postgis构建我的rails env。以下是我的db的扩展名:
List of installed extensions
Name | Version | Schema | Description
------------------+---------+------------+---------------------------------------------------------------------
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
postgis | 2.1.3 | public | PostGIS geometry, geography, and raster spatial types and functions
postgis_topology | 2.1.3 | topology | PostGIS topology spatial types and functions
(3 rows)
我也可以看到" t.spatial" location",limit:{:srid => 0,:type =>" geometry"}"在我的schema.rb中添加列并迁移数据库之后。
在控制台和rb文件中,我无法访问postgis方法,如:
> e.location = ST_GeomFromText('POINT(121.04238 24.777656)', 4326)
NoMethodError: undefined method `ST_GeomFromText' for main:Object
from (irb):2
from /usr/local/rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/commands/console.rb:90:in `start'
from /usr/local/rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/commands/console.rb:9:in `start'
from /usr/local/rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:69:in `console'
from /usr/local/rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /usr/local/rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/commands.rb:17:in `<top (required)>'
或者在ruby文件中:
@data.location = ST_GeomFromText('POINT(' + params[:longitude] +' ' + params[:latitude] + ')', 4326)
获取服务器错误:
NoMethodError (undefined method `ST_GeomFromText' for #<DataController:0x000000053ee388>):
我从互联网上尝试了一些想法,但无法弄清楚。