Prepare for the PgBouncer and IPv4 deprecations on 26th January 2024

Learn more

Getting started with Ruby on Rails and Postgres on Supabase


5 minute read

Every Supabase project comes with a full Postgres database, a free and open source database which is considered one of the world's most stable and advanced databases.

Postgres is an ideal choice for your Ruby on Rails applications as Rails ships with a built-in Postgres adapter!

In this post we'll start from scratch, creating a new Rails project, connecting it to our Supabase Postgres database, and interacting with the database using the Rails Console.

If you prefer video guide, you can follow along below. And make sure to subscribe to the Supabase YouTube channel!

Create a Rails Project

Make sure your Ruby and Rails versions are up to date, then use rails new to scaffold a new Rails project. Use the -d=postgresql flag to set it up for Postgres.

Go to the Rails docs for more details.


rails new blog -d=postgresql

Set up the Postgres connection details

Go to and create a new Supabase project. Save your database password securely.

When your project is up and running, navigate to the database settings to find the URI connection string.

Rails ships with a Postgres adapter included, you can simply configure it via the environment variables. You can find the database URL in your Supabase Dashboard.


export DATABASE_URL=postgres://

Create and run a database migration

Rails includes Active Record as the ORM as well as database migration tooling which generates the SQL migration files for you.

Create an example Article model and generate the migration files.


bin/rails generate scaffold Article title:string body:text
bin/rails db:migrate

Use the Model to interact with the database

You can use the included Rails console to interact with the database. For example, you can create new entries or list all entries in a Model's table.


bin/rails console


article = "Hello Rails", body: "I am on Rails!")
_10 # Saves the entry to the database

Start the app


bin/rails server

Run the development server. Go to in a browser to see your application running.

Update the app to show articles

Currently the app shows a nice development splash screen, let's update this to show our articles from the database:


Rails.application.routes.draw do
# Define your application routes per the DSL in
# Defines the root path route ("/")
root "articles#index"

Deploy to

In order to start working with, you will need flyctl, our CLI app for managing apps. If you've already installed it, carry on. If not, hop over to the installation guide. Once that's installed you'll want to log in to Fly.

Provision Rails with

To configure and launch the app, you can use fly launch and follow the wizard.

When asked "Do you want to tweak these settings before proceeding?" select y and set Postgres to none as we will be providing the Supabase database URL as a secret.

Set the connection string as secret

Use the CLI to set the Supabase database connection URI from above as a sevret which is exposed as an environment variable to the Rails app.



Deploy the app

Deploying your application is done with the following command:


fly deploy

This will take a few seconds as it uploads your application, builds a machine image, deploys the images, and then monitors to ensure it starts successfully. Once complete visit your app with the following command:


fly apps open

That's it! You're Rails app is up and running with Supabase Postgres and!


Supabase is the ideal platform for powering your Postgres database for your Ruby on Rails applications! Every Supabase project comes with a full Postgres database and a good number of useful extensions!

Try it out now at!

More Supabase

Share this article

Build in a weekend, scale to millions