Form objects – closer to the UI, farther from persistence
From a user interaction point of view, using almost any web application could be seen as a sequence of interleaving form submissions and link clicks. Although this is a very rough definition, it’s good enough to demonstrate that there are two primary ways an application deals with user-provided information: consuming incoming payloads and answering user-generated queries.
Let’s start with the first one.
In most cases (at least for Ruby on Rails applications), consuming a payload means creating or updating domain objects backed by Active Record models. The built-in #create
, #update
, and #destroy
Active Record methods can get us far beyond simple Create, Read, Update, and Delete (CRUD)operations, especially spiced with conditional or contextual validations and model callbacks—almost any sophisticated form could be processed without leaving the boundaries of a model object. But wait, didn’...