Last night I setup a PostGIS app at Heroku using activerecord-postgis-adapter. I thought I would share my experience in those hope that it saves someone the 3 hour detour I had. Jump to the bold part for the gotcha that roadblocked me.
I'm using:
rails (3.2.7)
activerecord-postgis-adapter (0.4.3)
rgeo (0.3.14)
rgeo-activerecord (0.4.5)
I had an app functioning perfectly on my local machine, talking to PostgreSQL 9.1.4 / POSTGIS="2.0.0 r9605"
Then I got to Heroku...
I provisioned one of their "Ronin" DBs ($200/mo ouch) - the lowest level that supports PostGIS:
heroku addons:add heroku-postgresql:ronin --postgis=true version=9.0
heroku pg:wait
heroku pg:promote HEROKU_POSTGRESQL_CYAN
heroku pg:psql
SELECT PostGIS_Full_Version();
POSTGIS="1.5.2" GEOS="3.3.3-CAPI-1.7.4" PROJ="Rel. 4.7.1, 23 September 2009" LIBXML="2.7.6" USE_STATS
What I failed to notice was that Heroku sets its database adapter using the scheme:// part of it's DATABASE_URL, and the default set for its postgis enabled database is still "postgres". You need to switch this from "postgres" to "postgis" by:
Run heroku config
Find the URL of your PostGIS enable databsae, e.g. for me it was HEROKU_POSTGRESQL_CYAN_URL
Then set DATABASE_URL to that URL, but with "postgis://" instead of "postgres://", e.g.:
Now I have fixed this everything is running flawlessly and identically locally and on Heroku.
___________________________________________________________________________
Here are some of the error signatures I ran into while debugging, for those folks Googling error strings trying to solve this:
When I tried to migrate, my migration that created a spacial index failed with:
PG::Error: ERROR: data type point has no default operator class for access method "btree"
HINT: You must specify an operator class for the index or define a default operator class for the data type.
: CREATE INDEX "index_user_feedback_on_latlon" ON "user_feedback" ("latlon")
I switched the migration to create the index using SQL instead, and got past that, only to have the app fail to boot with:
So I included rgeo, then got an error about set_rgeo_factory_for_column.
So I included rgeo-activerecord instead.
My point column was still being treated as just a string, however.
While debugging in the console I finally discovered that ActiveRecord::Base.connection was an ActiveRecord::ConnectionAdapters::PostgreSQLAdapter, which pointed me in the right direction.
-Sam.