PostGIS: Using Geospatial Data with Rails
Last updated October 21, 2021
Table of Contents
PostGIS is available in public beta. The beta is available on all Production tier databases and currently supports PostGIS version 2.5. It is available on the Dev or Basic Hobby tier plans. To enable PostGIS once connected to your PostgreSQL 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 to 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.