AI Summary
→ 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 INSIGHTS - **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. 💼 SPONSORS [{"name": "Judo Scale", "url": "https://judoscale.com"}, {"name": "Scout Monitoring", "url": "https://scoutapm.com"}] 🏷️ ActiveModel, Rails Architecture, Domain Objects, Database Serialization
