How to host Rails 7.2 on Railway (2024)

Here’s a tutorial to host a Rails 7.2 app on Railway, a cloud platform for deploying apps. Railway simplifies the deploy process with minimal configuration and has a hobby tier.

Prerequisites

  • Ruby and Rails installed locally.
  • Git installed and GitHub account (for storing your code).
  • Railway account (sign up at railway.app).

Step 1: Deploy Raills app on Railway

Click the button to deploy from Railway

Step 2: Configure PostgreSQL Database

Railway uses PostgreSQL for databases by default. You need to add it to your project.

Once added, Railway will provide you with a PostgreSQL connection URL. Update your config/database.yml file in the production section to use this URL:

production:
<<: *default
url: <%= ENV['DATABASE_URL'] %>

Step 3: Configure Secrets

Rails uses encrypted credentials. Ensure your secret keys and environment variables are correctly set up. Railway supports environment variables that you can set in the Railway dashboard.

  • SECRET_KEY_BASE: You can generate this by running:
rails secret

Then, in your Railway dashboard, add this value as an environment variable named SECRET_KEY_BASE.

Optional: Custom Domain Setup

If you want to use a custom domain for your app, you can configure it in the Railway dashboard. Follow the domain setup instructions here.

That’s it! Your Rails 7.2 application should now be live on Railway.

Leave a Reply

Your email address will not be published. Required fields are marked *