...

/

Active Model Is for Resource Modeling

Active Model Is for Resource Modeling

Learn about how the active model is used for resource modeling in our Rails application.

Active Record-like objects in Rails

Suppose we need to produce a report about the shipping zone to a given user for each widget from its manufacturer. A shipping zone is a rough approximation of how long it takes to mail something from one place to another, and we can calculate it based on two postal codes: the user’s and the manufacturer’s.

Let’s say we discover that our users refer to this as a user shipping estimate and that a list of widget names, IDs, and zone numbers can be fed into many downstream systems that already exist. Our job is to produce these values. Because we use resources for our routing, we’ll have a route like /user_shipping_estimates that, when given a destination postal code, will render a list of estimates based on our current database of widgets. Ideally, we could use objects that behave like Active Records and thus could be used with Rails’ form and URL helpers.

This is what the Active ...