Summary: this may work if you change it to:
Model.create(:the_name_of_your_geo_column => Point.from_x_y(10,20))
Longer version with a high probability of Rubinβs abuse: I barely wrote the word rb, but this week I saw too many wonderful projects to continue in a state of ignorance. Work with error messages in irb (starting from 0 in a language, but very familiar with PostGIS):
ActiveRecord::Base.establish_connection(:adapter=>'postgresql',:database=>'moveable') pt = TablePoint.new(:data => "Hello!",:geom => Point.from_x_y(1,2)) NameError: uninitialized constant Point
So require 'postgis_adapter' , but then:
PGError: ERROR: relation "table_points" does not exist
This should be the amazing ActiveRecord naming convention I've heard of. So create a table called table_points because I donβt know what the database model / synchronization methods are.
moveable=> create table table_points(data text, geo_something geometry);
Note that I used geometry , not geography , because my first instinct regarding your problem was that the modeling methods at the database adapter level created point types. Not at all. Then again in irb ,
pt = TablePoint.new(:geom => Point.from_x_y(1,2)) ActiveRecord::UnknownAttributeError: unknown attribute: geom
No attribute named geom? To see what happens again in psql :
moveable=> alter table table_points add column geom geometry; ALTER TABLE
Then:
irb(main):014:0> pt = TablePoint.new(:geom => Point.from_x_y(10,20)) => #<TablePoint data: nil, geo_something: nil, geom: #<GeoRuby::SimpleFeatures::Point:0x1022555f0 @y=20, @with_m=false, @x=10, @m=0.0, @with_z=false, @z=0.0, @srid=-1>> irb(main):015:0> pt.save => true
Unbelievable! What if I did:
pt = TablePoint.new(:data => 'is this even possible?', :geom => Point.from_x_y(38,121), :geo_something => Point.from_x_y(37,120)) => #<TablePoint data: "is this even possible?", geo_something: #<GeoRuby::SimpleFeatures::Point:0x102041098 @y=120, @with_m=false, @x=37, @m=0.0, @with_z=false, @z=0.0, @srid=-1>, geom:
Even more incredible!
moveable=> select * from table_points; data | geo_something | geom --------+-----------------+-------- | | 0101000000000 | 010100000000000 | | 010100000000000 | ...ble? | 00005E400000000 | 010000405E40 (4 rows)
I hesitate to publish this as an answer due to the fundamental lack of familiarity with Ruby, but the above works (reasonably, for me), and you can adapt it to your business.