This book takes you inside the Rails source code — not to teach you how to use Rails, but to show you how Rails uses Ruby.
10 chapters · 40,000 words · 300 pages · Rails 8.1
You'll trace a request from rails server to rendered HTML.
You'll see how ActiveRecord builds SQL through an abstract syntax tree.
You'll discover that Rails routing is powered by a finite automaton
straight out of a computer science textbook.
What's inside
Every explanation includes real code snippets with file paths so you can explore the source yourself.
Chapter 01
The Boot Process
60+ initializers, topologically sorted, running in under 2 seconds
Chapter 02
The Request Lifecycle
Every layer between Rack and your controller action
Chapter 03
Routing Internals
How resources :posts compiles into a finite automaton
Chapter 04
ActiveRecord
Arel, lazy evaluation, connection pooling, the visitor pattern
Chapter 05
Autoloading & Zeitwerk
Why const_missing was replaced and how Module#autoload works
Chapter 06
The Middleware Stack
25 layers you never see but depend on every request
Chapter 07
Security Internals
CSRF one-time-pad masking, SafeBuffer, encrypted credentials
Chapter 08
ActiveJob
The adapter pattern, GlobalID serialization, polynomial backoff
Chapter 09
Action Cable
Pub/sub architecture, WebSocket lifecycle, the reactor pattern
Chapter 10
Caching & Performance
Cache stores, Russian doll caching, HTTP ETags, query cache LRU
Is this for you?
This is not a beginner tutorial. It's the book you read after you've shipped Rails apps and want to understand why they work.
A taste
Every chapter traces through actual Rails code. No pseudocode. No hand-waving.
# railties/lib/rails/engine.rb, line 692 def build_middleware_stack config.middleware.build(endpoint) end # actionpack/lib/action_dispatch/middleware/stack.rb def build(app = Proc.new) middlewares.reverse.inject(app) do |a, e| e.build(a) end end # The entire middleware stack is built with # reverse.inject — each middleware wraps the next. # This is why order matters. This is why # the last middleware added runs first.
From Chapter 6: The Middleware Stack
300 pages of Rails internals, explained by someone who read every line so you don't have to.
Get Rails Under the HoodPDF + EPUB · Instant download · Free updates