1
我嘗試使用postgis構建我的rails env。以下是我分貝的擴展名:無法訪問postgis的方法
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 」位置「,限制:{:SRID => 0,:類型=>」 幾何 「}」 在我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>):
我嘗試了一些來自互聯網的想法,但無法弄清楚。
謝謝!!它工作,當我使用SQL代替RUBY代碼! – user3819512