-
Notifications
You must be signed in to change notification settings - Fork 19
Backend Pattern Form
Ferris Tseng edited this page Jan 2, 2020
·
4 revisions
A form is a pattern used to separate business logic from the controller. It typically includes logic for creating multiple objects and validations for those objects.
app/models/hearings/forms
- Includes
ActiveModel::Model
for validations - Usually includes a single public method
The Form pattern is only really appropriate if your controller route is responsible for manging multiple models, or there is some complex business logic that shouldn't live in the controller or the model.
Most people seem to suggest using the Form pattern in places you would otherwise use accepts_nested_attributes_for
. 1 They argue that accepts_nested_attributes_for
makes your model too concerned with how your view/controller collects data, and increases the size of your model.
- 1: https://forum.upcase.com/t/form-objects/2267
- https://thoughtbot.com/blog/activemodel-form-objects
Pattern | Description |
---|