Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Henning Koch, Thomas Eisenbarth

Rating 3.5 AI initial rating

When you started working with Rails some years ago, it all seemed so easy. You saw the blog-in-ten-minutes video. You reproduced the result. ActiveRecord felt great and everything had its place. Fast forward two years. Your blog is now a full-blown CMS with a hundred models and controllers. Your team has grown to four developers. Every change to the application is a pain. Your code feels like a house of cards. You turn to the internet for assistance, and find it filled with silver bullets. You should move away from fat controllers, it says. But do avoid fat models. And use DCI. Or CQRS. Or SOA. As you cycle through patterns, your application is becoming a patchwork of different coding techniques. New team members are having a hard time catching up. And youre beginning to question if all those new techniques actually help, or if youre just adding layers of indirection. You start missing the early days, when everything had seemed so easy and every new piece of code had its place. You actually liked ActiveRecord before it drowned you in a sea of callbacks. If only there was a way to do things «the Rails way» without having it fall apart as your application grows.

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A practical playbook for taming a Rails monolith that has outgrown its early elegance: instead of chasing architectural silver bullets, it shows how discipline, consistency, and Rails' own built-in tools can keep a growing codebase understandable and changeable. Best for mid-to-senior Rails developers and tech leads maintaining a large, aging application with a growing team. 【Book Arc】 - **Opening (~0%–10%)**: Frames the core problem — the "blog in ten minutes" app that quietly became a hundred-model CMS where every change hurts. Rejects the myth of an infinitely scalable architecture and sets the book's thesis: organize code so complexity grows "logarithmically," not linearly. - **Early (~10%–30%)**: Establishes the two foundational disciplines — a uniform, DRY controller blueprint built around RESTful CRUD mapping, and a disciplined return to ActiveRecord's intended lifecycle (callbacks, validations, dirty state) rather than fighting the library. - **Middle (~30%–50%)**: Extends the model layer beyond the database. Introduces ActiveModel-based "plain" model classes (e.g., a SignIn form object) and ActiveType to pull logic out of "controllers from hell," restoring clean form roundtrips and error handling. - **Late (~50%–75%)**: Moves into system-level concerns — organizing code for growth, managing gems and dependencies, the real cost of upgrades and monkey patches, and owning your stack rather than living on the bleeding edge. - **Ending (~75%–85%)**: Closes on testing as a design tool — choosing test types effectively, how many tests are enough, when to repeat yourself, and how to introduce tests into legacy code and skeptical teams. 【Key Takeaways】 - **Large apps are large — aim for logarithmic growth** (Opening): The book's central promise is not to eliminate complexity but to organize code so doubling models doesn't double problems. This reframing is the lens for everything that follows. - **Controllers deserve real discipline** (Early): A standard, reusable CRUD controller blueprint — with a scoped loader guarding model access and strong-parameter whitelisting — keeps controllers short, DRY, and consistent, and centralizes authorization concerns. - **Normalize every interaction to CRUD** (Early): Even non-obvious screens (canceling a subscription, batch image upload) can be modeled as create/destroy actions, letting one controller layout be reused with minimal variation. - **Work with ActiveRecord's lifecycle, not against it** (Early): Bypassing callbacks with ad-hoc methods invites invalid states; embracing validations and callbacks simplifies views, standardizes model behavior, and plays well with ecosystem gems. - **Push interaction logic into ActiveModel objects** (Middle): Form objects like a SignIn class (via a thin PlainModel/ActiveModel wrapper) handle validation and roundtrips without a database row, turning bloated controllers and hand-rolled views into clean `form_for` code. - **ActiveType rescues "controllers from hell"** (Middle): Extracting multi-model operations (e.g., account merging) into ActiveType objects shrinks controllers to near the default blueprint and restores automatic error highlighting. - **Gems and upgrades carry hidden costs** (Late): Every dependency raises upgrade cost and every monkey patch is a debt paid at upgrade time — so be deliberate about your stack and avoid the bleeding edge. - **Tests are a design instrument** (Ending): Test choices should guide better design; the book addresses test volume, strategic duplication, and pragmatic adoption in legacy apps and resistant teams. 【Reading Tips】 - **Deep-read the controller and ActiveRecord chapters** (Early): These are the most immediately actionable; adopt the CRUD blueprint and lifecycle discipline before anything else. - **Skim if you're pre-ActiveModel**: The PlainModel/ActiveType material assumes familiarity with ActiveModel; if you're on an older stack, focus on the concepts rather than the exact classes. - **Treat the late chapters as policy, not code**: The gem/stack-ownership and testing chapters are judgment calls — read them as guidance for team decisions rather than copy-paste recipes. - **Bring your own app**: This is a refactoring book; keep a specific pain point (a fat controller, a callback tangle) in mind and map each technique onto it as you read. 【Coverage Limits】 The excerpts cover the introduction, controller design, ActiveRecord lifecycle, ActiveModel/ActiveType form objects, and the table of contents for later chapters; the detailed content of the code-organization, gem-management, and testing chapters is only glimpsed through headings, so this guide characterizes those sections at a high level.
Page 4
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Did we just move code around? . . . . . . . . . . . . . . . . . . . . . . . . . . ....
View in text
Page 11
ionController 2 3 def index 4 load_notes 5 end 6 7 def show 8 load_note 9 end 10 11 def new 12 build_note 13 end 14 15 def create 16 build_note 17 save_note...
View in text
Page 17
= Invite.find(...) 2 invite.accepted = true 3 invite.save! That is unfortunate, since now we have an Invite record in a strange state: It is accepted, but no...
View in text
Excerpt 4
t' %> 17 18 <% if @target_missing %> 19 <div class="error"> 20 You must select a target account! 21 </div> 22 <% end %> 23 24 <%= select_tag :target_id, opti...
View in text
Excerpt 5
he sign up form requires confirmation of the user password) • Virtual attributes to support forms that do not map 1:1 to your database tables (e.g. tags are...
View in text
Excerpt 6
otice that we did not actually remove a single line of code. In fact we even gained a line or two by an additional class declaration. However, what used to b...
View in text
Excerpt 7
ontainer: 1 .social img { 2 width: auto; 3 float: none; 4 } We test our changes in the browser and all is well. We deploy the changes and inform our product...
View in text
Excerpt 8
s/stylesheets/application.css 1 /* 2 *= require ./normalize 3 *= require_tree ./blocks 4 */ BEM anti-patterns Using BEM is no guarantee for a maintain
View in text
Tags
AI categories
RubyBackendSoftware
Publisher: Lean Publishing
Publish Year: 2014
Language: English
Pages: 88
File Format: PDF
File Size: 6.9 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…