Understanding Rails

Understanding Rails · Season 2: Getting started

bin/rails, every day

Episode 13 · 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 3, November 21, 2026: A replay on a real app fixed the terminal output for starting the server, migrating and listing routes.
  • Version 2, November 20, 2026: The routes list no longer shows routes for notes, since generating only a model adds none.

server, console, generate, db, routes, test: the commands you'll run most.

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

Transcript

0:00 bin/rails, every day

Episode thirteen. Bin slash rails, every day. One command does most of your work in Rails. Here are the parts you'll use most.

0:12 The shape of a command

Every one starts the same way: bin slash rails, then what you want it to do. Add dash dash help to any of them to see its options.

0:22 server

Bin slash rails server starts Puma, on port three thousand. Leave it running while you work. In development, it reloads your code each time you save.

0:33 generate

Bin slash rails generate writes code to a pattern. Generate model Note, body colon text, makes four files: a migration, the model, its test, and sample data for tests.

0:45 db:migrate

The migration only describes a change. Bin slash rails db colon migrate makes it, and records the database's new shape in schema dot rb.

0:56 console

Bin slash rails console opens your app in Ruby, live. Create a note, count them, and try an idea before you write it into a file.

1:06 routes

Bin slash rails routes lists every address your app answers, and the controller action behind each one.

1:14 test

Bin slash rails test runs your tests. A new app has none yet, so it finishes in a blink. Rails tests use Minitest, built in.

1:24 A few more

A few more you'll meet soon. Db colon rollback undoes the last migration. Db colon seed loads seeds dot rb. And credentials colon edit opens your secrets.

1:37 Shortcuts

The ones you'll type most have one-letter forms: s for server, c for console, g for generate, and t for test.

Next: your first scaffold, a guided tour.

Check your understanding

  1. You run bin/rails generate model Note body:text. Which file does it NOT create?

    • A migration
    • app/models/note.rb
    • A controller for notes
    • test/fixtures/notes.yml
    Show answer

    A controller for notes. The model generator writes a migration, the model, its test, and fixtures. Controllers come from other generators. Source: Generating Models, The Rails Command Line (Rails Guides 8.1).

  2. You just ran bin/rails db:migrate. What happens to db/schema.rb?

    • Nothing, until you run a separate dump command
    • Rails rewrites it to match the database's new shape
    • You must edit it by hand to add the new table
    • It is deleted
    Show answer

    Rails rewrites it to match the database's new shape. After running migrations, Rails dumps the schema automatically, so schema.rb is always up to date. Source: Schema Management, The Rails Command Line (Rails Guides 8.1).

  3. Your last migration has a mistake, and you already ran it. Which command undoes it?

    • bin/rails db:seed
    • bin/rails db:migrate
    • bin/rails generate migration Undo
    • bin/rails db:rollback
    Show answer

    bin/rails db:rollback. db:rollback rolls the schema back to the previous version, undoing the last migration. Source: Migrations, The Rails Command Line (Rails Guides 8.1).

  4. What does bin/rails t run?

    • The tests
    • The server
    • The task list
    Show answer

    The tests. t is the short alias for test, just as s is server, c is console, and g is generate. Source: Overview, The Rails Command Line (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.