Skip to content

Backend Pattern Form

Ferris Tseng edited this page Jan 2, 2020 · 4 revisions

[Pattern] Form

Description

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.

Location

  • app/models/hearings/forms

Best Practices

  • Includes ActiveModel::Model for validations
  • Usually includes a single public method

Tradeoffs

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.

Resources

Examples in Caseflow

Additional Reading

Related Patterns

Pattern Description
Clone this wiki locally