# Ruby

A Ruby app deploys from its repository. Nimbus Land recognises it from your `Gemfile`, builds it and starts it, and for Rails fills in the settings a first deploy needs. Your own values always win.

## Quick start

A stock `rails new` app deploys as is. In the console, create an app from your repository with the deploy wizard. From the CLI, run this in the project directory:

```sh
nimbus deploy
```

Check these first:

- **Your server listens on `PORT`.** Puma and Rails already do. See [what every app needs](apps.md#what-every-app-needs).
- **If the app reads encrypted credentials,** have your `config/master.key` ready to paste as `RAILS_MASTER_KEY`. See [Rails](#rails).
- **If the app uses SQLite,** keep the storage volume the wizard offers, or every release starts with an empty database.

For non-Rails Ruby apps, `RACK_ENV=production` is suggested.

## Rails

A stock `rails new` app ships its own `Dockerfile`, and Nimbus Land builds from it. See [Dockerfile](dockerfile.md). A Rails app without a `Dockerfile` is built by Nimbus Land directly. Either way, it fills in what a first deploy needs:

- **`RAILS_ENV` and `RACK_ENV`** are set to `production` when your image doesn't set them.
- **`SECRET_KEY_BASE`** is generated and stored on the app when neither it nor `RAILS_MASTER_KEY` is set, so a stock app boots and sessions survive redeploys.
- **`RAILS_MASTER_KEY`** appears in the wizard as an empty secret. Paste your local `config/master.key` only if the app reads encrypted credentials. It is required when the repository ships `config/credentials.yml.enc` (or `config/credentials/production.yml.enc`) and `config/environments/production.rb` sets `config.require_master_key = true`; the wizard then holds **Deploy** until it is filled. From the CLI:

  ```sh
  nimbus env set RAILS_MASTER_KEY=- --secret < config/master.key
  ```

  See [Secret environment variables](secret-env-vars.md).
- **Storage volume.** A SQLite app keeps its databases under `storage/`. When the `Gemfile` names `sqlite3` and neither `pg` nor `mysql2`, the wizard offers a 1 GB volume at `/rails/storage` (`/workspace/src/storage` when Nimbus Land builds the app itself). Keep it, or every release starts with an empty database. From the CLI or API, attach a volume at the same path yourself. An app with a volume stops the old instance before starting the new one, so a redeploy has a few seconds with nothing serving. See [Volumes](volumes.md) and [SQLite databases](sqlite.md).
- **Background jobs.** When the `Gemfile` names `solid_queue`, `SOLID_QUEUE_IN_PUMA=true` is suggested so queued jobs run. Alternatively, add the **Solid Queue** worker in the **Background workers** section of the **Resources** tab. See [commands, workers and one-off runs](apps.md#commands-workers-and-one-off-runs).
- **Migrations.** The scaffold's entrypoint runs `bin/rails db:prepare` on every start. With Postgres, use the release command instead: the wizard suggests `bundle exec rails db:migrate`. See [release command](apps.md#release-command).

## Troubleshooting

For problems that aren't specific to Ruby, such as an app that never answers, see [Apps troubleshooting](apps.md#troubleshooting).

### Missing master key

The app fails at start with `Missing encryption key to decrypt file with`. Add `RAILS_MASTER_KEY` as a secret on the **Resources** tab (the contents of `config/master.key`, or `config/credentials/production.key`) and deploy again.

### `ArgumentError: unknown keyword: quirks_mode`

A fresh Rails 8.0 app fails `assets:precompile` with this message. Add `gem "json", "< 3"` to the `Gemfile`, run `bundle install`, commit and deploy again.

### The SQLite database is empty after a deploy

The app has no volume at its `storage/` path. Attach one as described under [Rails](#rails).
