
The Bike Shed 486: ActiveModel Everywhere
Dec 23, 2025
Aji and Sally dive into the magic of ActiveModel, exploring its use beyond ActiveRecord for a Rails-like API on non-AR objects. They share practical projects, like creating a DefaultThemes class, and discuss the benefits of attributes and validations for plain Ruby objects. Sally reflects on testing challenges faced without ActiveModel support. The duo also debates the nuances of Rails component naming and reminisces about the origins of helper methods, sparking ideas for a fun quiz to identify them.
AI Snips
Chapters
Transcript
Episode notes
Model Non-DB Objects As Resources
- Treat non-database domain objects as resources and give them a consistent ActiveModel-like API.
- Use attributes and validations from ActiveModel so controllers and views work the same way as with ActiveRecord.
Testing Pain From Skipping ActiveModel
- Sally built a small Ruby app without ActiveModel and found testing painful and repetitive.
- She later realized ActiveModel would have saved time by enabling FactoryBot and standard validators.
Reuse ActiveModel For Validation & Attributes
- Include ActiveModel attributes and validators in service-like classes to get instantiation and error handling for free.
- Call save-like methods that perform the resource's persistence logic and surface Rails-style errors on failure.
