PostGIS: Using Geospatial Data with Rails
Last updated August 08, 2023
Table of Contents
PostGIS is available on all Heroku Postgres plans and currently supports PostGIS versions 2.5 and 3.3. To enable PostGIS after connecting to your PostgreSQL database, run:
CREATE EXTENSION postgis;
Setting Up PostGIS with Rails
To use PostgreSQL as your database in Ruby applications, include the activerecord-postgis-adapter
gem in your Gemfile.
To fully take advantage of PostGIS with Rails on Heroku, 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.
gem 'activerecord-postgis-adapter'
To download and resolve all dependencies, run bundle install
. See the Ruby documentation for more information on getting set up with activerecord-postgis-adapter
.
After you’ve installed the gem, change the adapter to postgis
. See Rails Database Connection Behavior on how to modify your Rails connection adapter.