PostGIS: Using Geospatial Data with Rails
Last updated 17 August 2018
Table of Contents
PostGIS is available in public beta. The beta is available on all Production tier databases and currently supports PostGIS version 2.0. It is available on the Dev or Basic Hobby tier plans with Postgres version 9.4 and above. For Postgres 9.2 databases PostGIS is only available for those provisioned after April 20, 2013. To enable PostGIS once connected to your PostgreSQL 9.2 database run:
CREATE EXTENSION postgis;
Setting up PostGIS with Rails
To use PostgreSQL as your database in Ruby applications you will need to include the
activerecord-postgis-adapter gem in your Gemfile.
To fully take advantage of PostGIS with Rails on Heroku you’ll need configure your app with a custom buildpack which includes the appropriate system dependencies. This buildpack includes that support. Be sure to deploy the buildpack before building any gems.
bundle install to download and resolve all dependencies. For more information on getting setup with
activerecord-postgis-adapter you can visit their docs.
Once you’ve installed the gem you will need to change the adapter to “postgis”. You can see how to modify your Rails connection adapter here.