← Graph

Reform

tool 14 connections

Ruby gem by Nick Sutterer providing a declarative API for form objects with properties, collections, nested forms and contextual validations as a class separate from the model. Works with both HTML views (simple_form compatible) and API use cases. Motivated by dissatisfaction with Rails' accepts_nested_attributes_for, which only supported one form per model and forced ifs/else into models. Reform 2's runtime API centered on one mutable form instance used for rendering, validation and persistence (form.validate, form.save, populators for nested object creation); this proved error-prone and was the main source of bugs and misuse. Reform 3 (presented at wroclove.rb 2022) keeps the DSL but replaces the runtime with class methods returning immutable objects: Reform.present, Reform.validate (returns a result object), persist. Rewritten internally on top of Trailblazer activities for tracing and composable step pipelines, makes strong_parameters obsolete, supports dry-validation or Active Record validations, and can use ROM (change sets) instead of Active Record. Part of the Trailblazer framework but usable standalone; Reform 2 and Reform 3 can coexist in one app.

license
open-source
category
library
Discussed as the second gem encapsulating forms as objects with contextual validations.
about
Reform tool
Reform applied the same encapsulation idea to forms.
Main subject of the talk: Reform 2's mistakes and the Reform 3 redesign.
Concerns Reform 2's runtime API.
Retrospective question about Reform's design.
tool Reform
related_to
Reform was motivated by the limitations of accepts_nested_attributes_for when more than one form per model is needed.
tool Reform
related_to
Reform is part of the Trailblazer framework; Reform 3 is internally built on Trailblazer activities.
tool Reform
related_to
Reform integrates with Rails form helpers (e.g. simple_form) but is not tied to Rails.
tool Reform
related_to
Avo tool
Nick Sutterer proposes Reform as a possible replacement for Avo's form engine.
related_to
Reform tool
Contrasted with heavier form-object libraries that require constructing everything from scratch.
tool Reform
uses
Reform 2 used Representable internally as its parsing/serialization layer.
tool Reform
uses
Reform 3 supports dry-validation as a validation backend (preferred by Nick).
tool Reform
uses
ROM tool
Reform 3 can persist through a ROM adapter to produce change sets instead of using Active Record.
person Nick Sutterer
works_on
Reform tool
Author and maintainer of the Reform gem; currently redesigning it as Reform 3.
role: author

Provenance

Read by
21 extractions