V02 in Rails, wired rows: every edge drops, and the pages hold no logic

October 5, 2026 · ALA · V02 · Ruby · Rails · Hotwire · checklist

V01 left 24 scored findings and a list of options for each. V02 is V01 with those taken, iterated until the Ruby linter reports nothing at --super-strict and a hand walk of the Ruby checklist finds nothing to move. The shape is unchanged: a screen composition per request, domain abstractions wired port to port, Rails doing what it usually does around them. What moved is where the knowledge sits.

The layer map, declared

V01 had one domain layer and found fifteen peer edges in it that were really drops: a totals abstraction calling a pricing rule, a cart line rendering a product line. Spray names his own layers per project (§2.3.1), and the design doc had already said what V01’s map didn’t. V02 declares it:

layerholds
applicationScreens::*, controllers, page templates, routes
domainDomainAbstractions::* (stateful, ported) and views/components/ (a cart line, an order line, a price summary)
rulesRules::* (pricing, shipping, promo, volume tier, stock status, the product projection) and views/elements/ (a product line, a stock badge, tabs, a modal, a record form)
paradigmsDataFlow, Event, RequestResponse, Transitions, and the execution models LiveUpdate and PushLater
foundationPorts, Money, DomTargets, the gateway, the Active Record models

The honesty of a declared layer is in its contents: nothing in rules/ or elements/ reads a store or a word. A component renders elements; no component renders a component; no element renders an element with store knowledge.

Product data through a pull port

V01’s line tables each had belongs_to :product, and the storefront’s lines read the catalogue’s columns through the association: R10’s shared entity, found three times. V02 removes the associations. CartLines, SavedItems and Wishlist hold product ids and get an output port, products, a request/response: they ask for the projected rows of the ids they hold, and the screen wires all three to one ProductIndex instance configured with the catalogue’s model and the Rules::ProductRow projection.

class ProductIndex
  include Foundation::Ports
  input(:lookup, ProgrammingParadigms::RequestResponse) { |ids| @model.where(id: ids).to_h { [ _1.id, @project.(_1) ] } }
  def initialize(model:, project:) = (@model, @project = model, project)
end
@products = ProductIndex.new(model: Product, project: ProductRow.new(stock_rule:))
@lines.wire_to(@products, from: :products, to: :lookup)
@saved.wire_to(@products, from: :products, to: :lookup)
@wishlist.wire_to(@products, from: :products, to: :lookup)

The features share the identity key and nothing else, which is Spray’s own technique (§6.17.2): the catalogue’s shape can change without editing the cart. The cost is one more query per page where V01 joined; the join was the coupling.

Rows carry what the page needs

Under --super-strict, V01’s pages had loops (@s.rows.each), a comparison (wishlist_ids.include?), and persisted? ternaries: R11 logic in the composition’s templates. The checklist’s moves are to let a collection component iterate and to let the row carry the booleans the template needs. In Rails that is render collection:, which only works if nothing per row has to be computed in the page. V01 computed the URLs per row.

So in V02 a row carries its URLs, from a links lambda the screen configures with the route helpers, a small function passed in as configuration (§3.11.3):

@lines = CartLines.new(lines: CartItem, cart_id:, links: ->(id) { { quantity: urls.cart_item_path(id), remove: urls.cart_item_path(id),
                                                                     gift_wrap: urls.gift_wrap_cart_item_path(id), ... } })
<%= render partial: "components/cart_line", collection: @s.rows, as: :row,
      locals: { wishlist_ids: @s.wishlist_ids, t: @texts[:cart], labels: Screens::Store::STOCK_LABELS } %>

No component knows a route, no page computes one, and the cart line takes the wishlist’s ids and marks itself, which is the checklist’s “a row component takes the list it checks membership in”. The form’s URL comes from form_with model:, Rails’ own convention, instead of a ternary; the modal’s title comes from the page that opened it.

Names flow down

V01’s two R5 findings were names a screen and a component agreed on: the checkout’s status target and the modal’s Turbo frame. They are screen constants now, passed to the components as locals. The DOM ids and marker classes live updates target are Foundation::DomTargets, declared as a view helper, so elements render them and screens broadcast to them, both depending down. LiveUpdate and PushLater moved beside the DataFlow they build, and rendering a partial outside a request is the application’s business, in Screens::Partial.

Outcomes as outputs

Records emits created and updated instead of one saved, so the screen wires each to its own notice and its own live update (append for a new row, replace for an edited one) with no branch; show emits record apart from form. SubmitOrder emits its step after a failed submit, as CheckoutFlow already did, so the controller’s failure arm only renders. Undo.expired and SettleOrder.settled, wired by nobody, are gone. And current_cart_id reads session.fetch(:cart_id) { cart_id }: the one fallback, moved into the connection mechanism.

Checkout, drawn from the built graph

flowchart LR
  screen[[Screens::Checkout]]
  lines[lines: CartLines]
  pricing[pricing: PricingChoices]
  totals[totals: CartTotals]
  flow[flow: CheckoutFlow]
  charge[charge: Charge]
  settle[settle: SettleOrder]
  products[products: ProductIndex]
  lines -- products → lookup --> products
  lines -- contents → contents --> totals
  pricing -- discount → discount --> totals
  pricing -- shipping_method → shipping_method --> totals
  totals -- summary --> screen
  flow -- lines → lines --> lines
  flow -- step --> screen
  flow -- form --> screen
  flow -- blocked --> screen
  flow -- ready_to_pay --> job([DataFlow port])
  flow -- done --> screen
  charge -- charged → settle --> settle
  charge -- charged → succeeded --> flow
  charge -- declined → failed --> flow
  charge -- charged --> screen
  charge -- declined --> screen
  settle -- stock_changed → push --> stock([LiveUpdate])

The DataFlow port is the job: flow.ready_to_pay is wired to a port that enqueues PushLater, and the job rebuilds this same screen and pushes charge. The LiveUpdate is the stock broadcast to every open catalogue.

What it scores

V01V02
ala_lint default / --strict / --super-strict66 / 61 / 53100 / 100 / 100
Rules met under --super-strict (of 10 checked)410
Functions with no scored finding182 / 204208 / 208
Integration tests4850
Browser tests (Cuprite)none5
Non-blank lines in app/1,7921,877
Familiarity44

The two measures the linter reports and never scores remain, and should: the composition’s share of functions (42%, because a request-per-action framework has many actions and templates) and the average unit size (18 lines, because the rules and the one-port domain classes are deliberately small).

The hand walk’s judgement calls, recorded in the design: rules and elements as a declared layer (a map with one domain layer would report the same code as fifteen peer edges); peer_ok on the paradigms layer, because an execution model knows the interface it runs, which Spray keeps in one layer; the session fallback; the controllers’ routing arms; and cart_items still shared by the storefront and the portal as the lines abstraction both build on.

The browser suite

V01 was clicked through by hand. V02 has five system tests through Capybara and Cuprite (Chrome over the DevTools protocol, no Node): the modal form validating live and a saved product landing in the list; tabs and the shipping choice submitting itself; a removal offering undo and expiring on its own; the checkout’s address, payment, the job performed, and the live redirect to the success page; and the portal earning a volume tier and validating a purchase order before submitting. Broadcasts reach the browser because the system-test process swaps Action Cable’s test adapter for the in-process async one.

The suite earned its keep on its first run. It found that the live-validation fetch forwarded _method=patch to a POST-only route, that typing while a validation reply replaced the form lost keystrokes (now debounced, with the typed value restored and stale replies dropped), and that the portal’s submit route was POST while form_with model: sends PATCH. The integration tests post directly and never saw any of the three.

What it costs

For a Rails team, V01 is the smaller step: one new vocabulary (wire_to, on) and otherwise stock Rails. V02 is the shape to grow into once the linter is in CI, because every one of its changes was a finding first.

The code is in ala_variants_ruby/v02-wired-rows.

← all posts