Exploring Rails anti-patterns
summary
A small Rails 7 app exists to prove each example actually works: controllers move business logic into a service object (placed order) and password resets live in a PasswordsResetController; long ActiveRecord queries become scopes or query objects and N+1s disappear by using includes and eager loading; performance finds come from the bullet gem and strict_loading or Rack Mini Profiler; null objects, presenters/decorators and delegate reduce view coupling; callbacks that hit external systems become background jobs or timed Faraday calls (timeout cut from 60s to 3s); tests cover refactors and delegation.
AI-written summary · about
chapters (20)
- 0:00Introduction
- 1:49Anti-patterns and refactoring
- 2:52Fat controllers and logic
- 6:44Non-standard controller actions
- 8:30Separate controllers for actions
- 10:19Spaghetti SQL and Active Record
- 11:24N+1 queries and eager loading
- 14:32Law of Demeter and coupling
- 16:21Null object pattern for nil
- 19:11Overloaded views and presenters
- 22:43View helpers and view models
- 25:57Strict locals and magic comments
- 27:47Fat models and God objects
- 30:15Breaking down large models
- 31:44Rails callbacks pitfalls
- 33:30Service objects instead of callbacks
- 34:58Concerns vs pure Ruby objects
- 36:25Testing delegation
- 37:08Slow API calls and background jobs
- 38:18Summary
related talks
36mIn Relentless Pursuit of REST
41mOff the Tracks - Challenging the Rails Mindset
40mInto the Heart of Darkness: Rails Anti-Patterns
38mRails hurts, because you're using it wrong. Let's fix that
42mPowerful Rails Features You Might Not Know
34mSimple and Elegant Rails Code with Functional Style
26mDon't Rewrite Your Framework
35mRails vs. Object Oriented Design
