Chapter 2Building Models with Active Model

  • Active Model and its modules

  • How to make an object comply with the Active Model API required by Rails

  • Rails’s validators and Ruby-constant lookup

In the previous chapter, we talked briefly about Abstract Controller and how it reduced code duplication in the Rails source code since it’s decoupled from both Action Mailer and Action Controller. Now let’s look at Active Model, which is similar.

Active Model was originally created to hold the behavior shared between Active Record and Active Resource.[15] As with Abstract Controller, the desired functionalities can be cherry-picked by including only the modules you need. Active Model is also responsible for defining the application programming interface ...

Get Crafting Rails 4 Applications, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.