Decouple Your Models with Form Objects
summary
Builds a three-step onboarding wizard for dog-walking companies and shows that form objects remove model cruft: validations live on forms, not in fat models, and nested attributes and conditional state machines disappear. Uses plain Ruby form objects with activemodel::model then refactors to use the Reform gem (Trailblazer) to get prepopulate/populator behavior, collections, and composition. Saves each step transactionally, keeps controllers RESTful, makes tests fast, and reduces boilerplate compared side‑by‑side with a hand‑rolled solution.
AI-written summary · about
chapters (7)
- 0:00Start
- 12:41initializing the nested fill method
- 13:06define the properties inside the collection
- 14:36add a pre-populated method to the collection
- 17:32adding and removing addresses
- 20:15add or remove multiple addresses
- 23:31testing the form objects
related talks
18mOBJECTIFY YOUR FORMS: BEYOND BASIC USER INPUT
38mRails hurts, because you're using it wrong. Let's fix that
38mRefactoring Fat Models with Patterns
35mUltra Light and Maintainable Rails Wizards
37mPatters to deal with big ActiveRecord models
33mAll you need to know to build Dynamic Forms (JS FREE)
41mOff the Tracks - Challenging the Rails Mindset
39mExploring Rails anti-patterns
