PostGIS: Using Geospatial Data with Rails
Last updated November 21, 2022
Table of Contents
PostGIS is available in public beta. The beta is available on all Standard-tier or higher databases and currently supports PostGIS version 2.5. 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.
bundle install to download and resolve all dependencies. For more information on getting setup with
activerecord-postgis-adapter you can visit their docs.
After you’ve installed the gem, change the adapter to “postgis”. You can see how to modify your Rails connection adapter here.