Skip to content
Ruby on Rails

Deploy a Ruby on Rails application

Ruby on Rails is a full-stack web framework with routing, database access, background jobs and server-rendered views. Clever Cloud’s Ruby runtime installs the application’s bundled gems and starts its config.ru with Puma.

Prepare the application

Your project must contain:

  • A Gemfile with rails, puma and the adapter for your database
  • A committed Gemfile.lock that supports x86_64-linux
  • A config.ru file, generated by Rails

Declare a supported Ruby release in the Gemfile to keep local and deployed environments consistent:

Gemfile
ruby "~> 3.4"

Run bundle install after changing the dependencies and commit the resulting lockfile.

Create the application and database

Install Clever Tools, log in, then create a Ruby application from the project directory:

npm i -g clever-tools
clever login

git init
clever create -t ruby -a myRailsApp

Clever Tools targets your personal organisation by default. To use another organisation, add --org ORGANISATION or -o ORGANISATION when you create or link the application.

You can display your application’s URL or add a custom domain. A custom domain also requires DNS configuration:

clever domain
clever domain add your.website.tld

Create a PostgreSQL add-on and link it to the application:

clever addon create postgresql-addon myRailsDb -p dev -l myRailsApp

Linking the add-on injects POSTGRESQL_ADDON_URI and the individual connection variables into the application. Configure a single production database with this URI:

config/database.yml
production:
  <<: *default
  url: <%= ENV.fetch("POSTGRESQL_ADDON_URI") %>

If your application uses multiple Rails databases, configure each production connection explicitly instead of replacing the complete production section with this single-database example.

Configure the deployment

Generate a secret key and configure idempotent database preparation and asset compilation:

clever env set SECRET_KEY_BASE "$(openssl rand -hex 64)"
clever env set CC_RAKEGOALS "db:prepare,assets:precompile"
clever env set STATIC_FILES_PATH public

CC_RAKEGOALS runs the comma-separated Rake tasks during each new build. STATIC_FILES_PATH lets NGINX serve the files generated under public while other requests are forwarded to Puma.

Deploy

Commit the application and deploy it:

git add .
git commit -m "First deploy"

clever deploy
clever open

Rails reads linked add-on variables through ENV, as it does for any other environment variable.

Learn more

Last updated on