Post

Modern Rails 8: The Full-Stack Developer Cheatsheet

Introduction

As we enter the era of Rails 8, the framework has evolved significantly, focusing on full-stack simplicity, built-in performance, and security. For experienced developers, the shift is from “how to wire things together” to “how to leverage the built-in ecosystem.”

Modern Rails 8 Highlights

  • The 3 Solids: Solid Queue, Solid Cache, and Solid Cable provide DB-backed infrastructure, replacing external dependencies (Redis/Memcached) for many applications.
  • Kamal: Zero-downtime, container-based deployment out of the box.
  • Import Maps: Say goodbye to complex Node.js build steps for standard applications.
  • Turbo & Stimulus: Seamless reactive UIs without writing custom JavaScript SPAs.

1. Fundamentals & Architecture

  • Ruby: Master Procs, Lambdas, Blocks, and Meta-programming for clean DSLs.
  • MVC: Keep controllers lean. Business logic belongs in Service Objects or Model methods.
  • Conventions: Rails is opinionated. Follow the naming conventions to avoid configuration hell.

2. Active Record & Database

  • Models: Use has_many, belongs_to, has_one :through to define relationships.
  • Schema: Always index foreign keys. Use add_reference in migrations.
  • Optimization: Avoid N+1 queries using .includes, .preload, or .eager_load.

3. The Hotwire Stack

  • Turbo Drive: Speed through native page transitions.
  • Turbo Frames: Isolate page segments for partial updates.
  • Turbo Streams: Push updates to UI via WebSockets.
  • Stimulus: Data-attributes driven JS. Connect JS behavior to HTML naturally.

4. Modern Infrastructure (The 3 Solids)

  • Solid Queue: Replace Sidekiq with DB-backed jobs.
  • Solid Cache: High-performance caching stored in your database.
  • Solid Cable: DB-backed real-time communication.

Caching Layers Overview Rails Caching Flow

5. Security & PWA

  • Security: Strong params are non-negotiable. Use has_secure_password for auth.
  • PWA: Use manifest files and service workers for basic offline capabilities and “app-like” behavior on mobile.

6. Deployment

  • Kamal: Standard for deploying to bare metal or any VPS. Use Docker for environment consistency.
  • Cloud: Rails handles secrets (bin/rails credentials) and environments (dev, test, production) natively.

Quick Reference Checklist

  • Eager Loading: Use includes(:assoc) to stop N+1.
  • Background Jobs: Always favor ActiveJob for async work.
  • Authentication: Use has_secure_password or standard gems like Devise for robust systems.
  • Authorization: Use Pundit or CanCanCan to manage roles.
  • Testing: Minitest is the default. Keep system tests for user flows.
  • Debugging: binding.irb is your best friend. Check logs frequently.

This cheatsheet focuses on the “modern” way—prioritizing convention over configuration to ship features faster.

This post is licensed under CC BY 4.0 by the author.