487: ActiveModel custom attributes
Episode
37 min
Read time
2 min
AI-Generated Summary
Key Takeaways
- ✓Custom Attribute Pattern: Store primitive values like strings or integers in the database, but access them as rich objects with domain methods. Phone numbers stored as strings become PhoneLib objects with formatting, validation, and country detection capabilities.
- ✓Query Integration: Custom attributes enable querying with rich objects instead of raw values. Pass a PhoneLib object directly into ActiveRecord where clauses without worrying about format matching, as the attribute handles serialization automatically during database operations.
- ✓Normalization Strategy: Implement database normalization in custom attributes to enable reliable querying and indexing. Store phone numbers in E164 format or percentages as decimals consistently, while presenting user-friendly formats in views without scattered conversion logic throughout the codebase.
- ✓Abstraction Benefits: Consolidate scattered helper methods and conversion logic into single attribute classes. Replace repeated divide-by-100 and times-100 operations for percentages with domain objects that handle display formatting, mathematical operations, and storage transparently across multiple models.
What It Covers
Joelle and Sally explore ActiveModel custom attributes in Rails, examining how to create rich objects that serialize to database primitives while maintaining domain logic, with examples including phone numbers, money, and percentages.
Key Questions Answered
- •Custom Attribute Pattern: Store primitive values like strings or integers in the database, but access them as rich objects with domain methods. Phone numbers stored as strings become PhoneLib objects with formatting, validation, and country detection capabilities.
- •Query Integration: Custom attributes enable querying with rich objects instead of raw values. Pass a PhoneLib object directly into ActiveRecord where clauses without worrying about format matching, as the attribute handles serialization automatically during database operations.
- •Normalization Strategy: Implement database normalization in custom attributes to enable reliable querying and indexing. Store phone numbers in E164 format or percentages as decimals consistently, while presenting user-friendly formats in views without scattered conversion logic throughout the codebase.
- •Abstraction Benefits: Consolidate scattered helper methods and conversion logic into single attribute classes. Replace repeated divide-by-100 and times-100 operations for percentages with domain objects that handle display formatting, mathematical operations, and storage transparently across multiple models.
Notable Moment
Sally realizes she has been using custom attributes through the MoneyRails gem without understanding the underlying pattern, discovering how this approach eliminates the mental overhead of remembering which format percentages use in different database columns.
You just read a 3-minute summary of a 34-minute episode.
Get The Bike Shed summarized like this every Monday — plus up to 2 more podcasts, free.
Pick Your Podcasts — FreeKeep Reading
More from The Bike Shed
498: Season 2 Recap
Mar 17 · 37 min
The Model Health Show
The Menopause Gut: Why Metabolism Changes & How to Reclaim Your Body - With Cynthia Thurlow
Apr 27
More from The Bike Shed
497: Diagrams we love
Mar 10 · 41 min
The Rest is History
664. Britain in the 70s: Scandal in Downing Street (Part 3)
Apr 26
More from The Bike Shed
We summarize every new episode. Want them in your inbox?
Similar Episodes
Related episodes from other podcasts
The Model Health Show
Apr 27
The Menopause Gut: Why Metabolism Changes & How to Reclaim Your Body - With Cynthia Thurlow
The Rest is History
Apr 26
664. Britain in the 70s: Scandal in Downing Street (Part 3)
The Learning Leader Show
Apr 26
685: David Epstein - The Freedom Trap, Narrative Values, General Magic, The Nobel Prize Winner Who Simplified Everything, Wearing the Same Thing Everyday, and Why Constraints Are the Secret to Your Best Work
The AI Breakdown
Apr 26
Where the Economy Thrives After AI
Cognitive Revolution
Apr 26
AI in the AM: 99% off search, GPT-5.5 is "clean", model welfare analysis, & efficient analog compute
This podcast is featured in Best Cybersecurity Podcasts (2026) — ranked and reviewed with AI summaries.
You're clearly into The Bike Shed.
Every Monday, we deliver AI summaries of the latest episodes from The Bike Shed and 192+ other podcasts. Free for up to 3 shows.
Start My Monday DigestNo credit card · Unsubscribe anytime