--- title: 'Use Supabase with Ruby on Rails' subtitle: 'Learn how to create a Rails project and connect it to your Supabase Postgres database.' breadcrumb: 'Framework Quickstarts' --- <$Partial path="quickstart_create_project.mdx" /> Save your database password securely. You need it for the connection string. This guide uses Rails' own Active Record models and migrations, not the shared `instruments` sample table used by other quickstarts. ## 2. Create a Rails project [#create-an-app] With your Ruby and Rails versions up to date, run `rails new` in your terminal to scaffold a project. Use the `-d=postgresql` flag to set it up for Postgres. For more information, see [Getting Started with Rails](https://guides.rubyonrails.org/getting_started.html) in the Rails guides. ```bash rails new blog -d=postgresql cd blog ``` ## 3. Set up AI tooling (optional) [#set-up-ai-tooling] <$Partial path="quickstart_ai_tooling.mdx" /> ## 4. Set up the Postgres connection details [#set-up-the-postgres-connection-details] <$Partial path="quickstart_connection_string.mdx" /> Set the connection string as an environment variable. Rails reads `DATABASE_URL` from the environment and connects with it, so you don't need to edit `config/database.yml`. The export applies to the current shell session, so run it in the same shell as the Rails commands in the following steps. ```bash export DATABASE_URL=postgres://postgres.[PROJECT-REF]:[YOUR-DATABASE-PASSWORD]@[POOLER-HOST]:5432/postgres?sslmode=require ``` ## 5. Create and run a database migration [#create-and-run-a-database-migration] Rails includes Active Record as the ORM, and migration tooling that generates the SQL migration files for you. Create an example `Article` model and generate the migration files. ```bash bin/rails generate model Article title:string body:text bin/rails db:migrate ``` ## 6. Use the model to interact with the database [#use-the-model-to-interact-with-the-database] You can use the included Rails console to query and update the database. For example, you can create new entries or list all entries in a model's table. ```bash bin/rails console ``` ```rb name=irb article = Article.new(title: "Hello Rails", body: "I am on Rails!") article.save # Saves the entry to the database Article.all ``` ## 7. Start the app [#start-the-app] Run the development server. Go to `http://127.0.0.1:3000` in a browser to see your app running. ```bash bin/rails server ``` <$Partial path="quickstart_going_to_production.mdx" /> ## Next steps Build on this app with the following resources: - Set up [Auth](/docs/guides/auth) for your app - [Insert more data](/docs/guides/database/import-data) into your database - Upload and serve static files using [Storage](/docs/guides/storage)