Learn Ruby on Rails

Convention-over-configuration Ruby framework for full-stack web apps

20 lessons · 5 hours · 4 levels · covers Ruby on Rails 8.0

Ruby on Rails is a full-stack web framework built on the MVC pattern: Active Record for data, Action Controller and Action View for requests and HTML, Hotwire for interactive front ends, plus built-in jobs, mail, caching and WebSockets. Its conventions let small teams ship complete products quickly, and it runs companies like Shopify, GitHub and Basecamp. Rails 8 adds a built-in authentication generator, database-backed queues and caches, and Kamal deployments.

Before you start

Ruby on Rails builds on these; the tree links to the exact lessons you need.

How deep do you want to go?

1. EssentialsRead and write simple code, do the everyday basics7 lessons · 1 hour in total
2. PracticalUse it productively at work, with the usual idioms13 lessons · 3 hours in total
3. AdvancedThe less common features, performance and trade-offs17 lessons · 4 hours in total
4. ExpertInternals and the edge cases experts know20 lessons · 5 hours in total

The Ruby on Rails tree

Ruby on RailsCreating an app and its conventionsCreating an app andits conventionsRoutingRoutingControllers and actionsControllers andactionsViews, layouts and partialsViews, layouts andpartialsMigrations and the schemaMigrations and theschemaActive Record basicsActive Record basicsForms and strong parametersForms and strongparametersValidations and callbacksValidations andcallbacksAssociations and eager loadingAssociations andeager loadingScopes and advanced queriesScopes andadvanced queriesHotwire: Turbo and StimulusHotwire: Turbo andStimulusAuthentication with the Rails 8 generatorAuthentication withthe Rails 8 generatorTesting Rails appsTesting Rails appsGems and BundlerGems and BundlerClasses and objectsClasses and objectsCreating and altering tablesCreating and alteringtablesBlocks and iteratorsBlocks and iteratorsProcs, lambdas and closuresProcs, lambdas andclosuresInner joinsInner joinsTesting with Minitest and RSpecTesting with Minitestand RSpec
Essentials and Practical shown (13 of 20 lessons); the full list is below. Click a lesson to read it.

All 20 lessons, in order

Rails fundamentals

  1. Creating an app and its conventions · Essentials · 10 min

    Generate a Rails 8 app, run it, and learn the directory layout and the conventions that make Rails work.

  2. Routing · Essentials · 12 min

    Map URLs to controller actions in config/routes.rb with resources, nested routes, root and named route helpers.

  3. Controllers and actions · Essentials · 12 min

    Write controller actions that read params, load models, and render, redirect or respond with the right status.

Views, forms and Hotwire

  1. Views, layouts and partials · Essentials · 12 min

    Render HTML with ERB templates, layouts and partials, and use helpers like link_to and the flash.

  2. Forms and strong parameters · Essentials · 14 min

    Build forms with form_with, show validation errors, and whitelist input with params.expect.

  3. Hotwire: Turbo and Stimulus · Practical · 16 min

    Make server-rendered pages feel like an SPA with Turbo Drive, Frames and Streams, and sprinkle behaviour with Stimulus.

  4. Authentication with the Rails 8 generator · Practical · 15 min

    Add sign-in with bin/rails generate authentication, has_secure_password, sessions and rate limiting.

Active Record

  1. Migrations and the schema · Essentials · 12 min

    Evolve the database with migrations, references and indexes, and understand schema.rb.

  2. Active Record basics · Essentials · 14 min

    Create, read, update and delete records with Active Record, and build lazy, chainable queries.

  3. Validations and callbacks · Practical · 14 min

    Validate models before saving, read errors, and use lifecycle callbacks carefully.

  4. Associations and eager loading · Practical · 15 min

    Connect models with belongs_to, has_many and has_many :through, and prevent N+1 queries with includes.

  5. Scopes and advanced queries · Practical · 14 min

    Name reusable queries with scopes and class methods, and use joins, grouping, merges and batching.

  6. Concerns and app architecture · Advanced · 14 min

    Share behaviour with ActiveSupport::Concern, and decide when to reach for POROs, service objects and form objects.

Jobs, caching and APIs

  1. Testing Rails apps · Practical · 15 min

    Test models, controllers and full user flows with Minitest, fixtures, integration tests and system tests.

  2. Background jobs with Active Job · Advanced · 14 min

    Run slow work in the background with Active Job and Solid Queue, with retries, scheduling and recurring tasks.

  3. Caching · Advanced · 15 min

    Speed up pages with fragment and Russian-doll caching, low-level Rails.cache, and HTTP conditional GETs.

  4. Building JSON APIs · Advanced · 14 min

    Build JSON APIs with Rails: API-only apps, rendering JSON, error handling, versioning and token authentication.

Internals and deployment

  1. Autoloading, Zeitwerk and boot · Expert · 14 min

    Understand how Zeitwerk maps files to constants, how reloading and eager loading work, and the Rails boot process.

  2. Rack and the middleware stack · Expert · 14 min

    See how a request travels from Puma through Rack middleware and the router to a controller, and write your own middleware.

  3. Deployment, Puma and performance · Expert · 16 min

    Deploy with Kamal 2, tune Puma workers and threads, size connection pools, and find production bottlenecks.