Skip to main content
The Bike Shed

487: ActiveModel custom attributes

37 min episode · 2 min read
·

Episode

37 min

Read time

2 min

Topics

Software Development, Philosophy & Wisdom, Science & Discovery

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.

Know someone who'd find this useful?

Episode Transcript

Auto scaling is a simple concept. Automatically add resources when needed and automatically shut them down to avoid paying for excess capacity. How hard could that be? If you've set up auto scaling yourself, you know it's not that easy, especially using the native auto scalers on platforms like AWS and Heroku. That's why you need Judo Scale. Judo Scale is auto scaling as a service, and they make auto scaling simple and easy, as it should be. You can use Judo Scale on AWS, Heroku, Render, fly.io, and more. It's free for low traffic apps and unlimited plans start at $25 per month. Autoscale on easy mode at judoscale.com. Hello, and welcome to another episode of the Bike Shed, a weekly podcast from your friends at Thoughtbot about developing great software. I'm Sally Hall. And I'm Joelle Kinville. And together we're here to share a bit of what we've learned along the way. So Joelle, what's new in your world? So it's really exciting this week is Thoughtbot's yearly, Ralphapalooza, which is our sort of end of the year hackathon. And the way we do it is that in the lead up to it, people will pitch project ideas, something that they think they can complete within two days. And you need to have at least a couple other people to join on your idea for it to be a go because this is meant to be something that's collaborative. And then once you have that, if you can attract enough people to join your idea, then you have two days to go do a thing. And then at the end of the the second day, typically, you'll present it to the rest of the company. It's a pretty exciting way to wrap up the year. And I think the types of projects can be really broad. This is not necessarily just build an app. It could be doing a particular type of write up, doing features on an existing project, some internal software. I believe we have a team that's working on conference talk ideas for CFPs next year. So there's room for a lot of different types of creativity. I've even participated some years in things where we did, like, a a mostly design project and came up with, like, a visual representation of the work we'd done that year. Or one year, we even collaborated on some volunteer work, which was pretty exciting. Yeah. So people can take it in a lot of different directions. The idea is that you have to do it with other people. So it has to be collaborative and there has to be some kind of artifact at the end that you can share. So you don't want to just be like, I don't know, I did some things. There has to be something tangible that you can that you can share with others. So what are you doing this year? I'm on a group that's looking to do, some more, …

Get the full transcript (6,624 words) + summary by email — free

One-time email with the complete transcript and AI summary of this episode. No account needed.

One email, no spam. We’ll also show you what SignalCast does.

Browse all The Bike Shed transcripts →

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 — Free

Keep Reading

Books, tools, and gear mentioned in this episode

SignalCast may earn commission on purchases via these links.

Tools

  • 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.

More from The Bike Shed

We summarize every new episode. Want them in your inbox?

Similar Episodes

Related episodes from other podcasts

Explore Related Topics

This podcast is featured in Best Cybersecurity Podcasts (2026) — ranked and reviewed with AI summaries.

Read this week's Software Engineering Podcast Insights — cross-podcast analysis updated weekly.

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 one show.

Start My Monday Digest

No credit card · Unsubscribe anytime