Understanding Rails

Understanding Rails · Season 2: Getting started

A tour of a new app

Episode 11 · overview · about 2 minutes · Rails 8.1 · by

How was this episode?

The series' author reads every note, and no one else sees it. When something is wrong or unclear, it gets fixed and the episode re-cut. How this series stays right.

Was it clear?

Not endorsed yet. Are you a Rails developer? What's an endorsement?

Endorse this version To endorse: create an account, confirm your email, then link GitHub.

What changed

  • Version 2, November 20, 2026: The Solid trio each get their own database only in production, not in development.

Every folder and file rails new writes, and which ones you will touch.

Free to watch. If it helped, support the series.

Transcript

0:00 A tour of a new app

Episode eleven. A tour of a new app. Rails new wrote dozens of files. You'll touch a few every day, and leave the rest alone for a long time.

0:13 The top level

At the top, four folders hold most of your work: app, config, db, and test. The rest is plumbing that Rails looks after.

0:23 app/

App holds your code, sorted by kind. Models, views, and controllers, plus helpers, jobs, mailers, assets, and javascript.

0:33 config/

Config sets the app up. Routes dot rb maps addresses to controllers. Database dot yaml names the databases. And environments holds one file each for development, test, and production.

0:47 Credentials

Credentials dot yaml dot enc holds your secrets, encrypted. Master dot key unlocks them. Rails keeps the key out of git for you. Never share it.

0:58 db/

Db holds seeds dot rb today, and your migrations and schema soon. The cache, queue, and cable schemas belong to the Solid trio, which each get their own database in production.

1:11 bin/

Bin holds the commands you run. Bin slash rails for almost everything, bin slash dev to start working, and bin slash setup on a fresh checkout.

1:22 bin/ci

Bin slash ci runs every check before you push: the setup, a style check, three security audits, and the tests.

1:31 Shipping files

The Dockerfile, config slash deploy dot yaml, and the dot kamal folder are for shipping. We'll open them in the production season.

1:41 The Gemfile

Last, the Gemfile lists the gems your app uses, and Gemfile dot lock pins their exact versions, so every computer runs the same code.

1:51 Next

That's the tour. Next, the Rails way: why everything has its place.

Check your understanding

  1. You clone a teammate's Rails app. config/credentials.yml.enc is there, but config/master.key is not. Why?

    • Rails added the key to .gitignore when it made it, so it was never committed
    • Rails deletes the key after each deploy
    • The key is stored inside credentials.yml.enc
    • Your teammate forgot to run bin/setup
    Show answer

    Rails added the key to .gitignore when it made it, so it was never committed. When Rails creates a key file, it adds it to .gitignore so it stays out of git history. Ask your team for the key. Source: EncryptionKeyFileGenerator (Rails source, v8.1.4.1).

  2. Is it safe to commit config/credentials.yml.enc to git?

    • No, it holds your secrets in plain text
    • Yes, because it is encrypted, as long as the master key stays safe
    • Only if the repository is private
    • Only after you delete secret_key_base from it
    Show answer

    Yes, because it is encrypted, as long as the master key stays safe. The file is encrypted, so it can live in version control. The master key is the part you must never commit. Source: Custom Credentials, Securing Rails Applications (Rails Guides 8.1).

  3. Which of these is one of the steps bin/ci runs in a new Rails 8.1 app?

    • System tests in a browser
    • A deploy with Kamal
    • Brakeman, a security scan of your code
    • A database backup
    Show answer

    Brakeman, a security scan of your code. config/ci.rb runs setup, RuboCop, the gem and import map audits, Brakeman, and the tests. System tests are there, but commented out. Source: config/ci.rb template for new apps (Rails source, v8.1.4.1).

  4. Which top folder holds your migrations and your database schema?

    • app
    • config
    • storage
    • db
    Show answer

    db. db holds the current database schema and the migrations. storage holds the SQLite database files themselves. Source: Directory Structure, Getting Started with Rails (Rails Guides 8.1).

Sources

Every example in this episode was run on Rails 8.1.4.1 and Ruby 4.0.2.

Comments

Sign in to comment or sign up.