← Graph

Extracting logic from templates with Hanami Views

talk 17 connections

Single-speaker talk at wroclove.rb 2024 by Sebastian Wilgosz, aimed at the ~99% of the audience who don't use Hanami daily. Opens by framing Hanami as a small (~5% of the Ruby web market), modular, courageous alternative to Rails — projects and careers are built on it, companies earn millions on top of it. Wilgosz argues Rails has deep-rooted issues (N+1 queries being an example almost unique to the Rails ecosystem, lack of built-in abstractions beyond MVC + helpers, endless community debates around service/view/form objects/decorators, an 'all or nothing' Gemfile where Active Record and Active Support are hard to replace due to Ruby monkey patches). Hanami, by contrast, is modular like Roda — you can disable router, controller, validations, persistence, or views entirely. With the 2.1 release, the Hanami View gem is officially done and framework-agnostic, usable in any Ruby app. Main walkthrough: a simple registration form (text fields, checkbox, icons, top-level + per-field validation errors) hides lots of presentation logic. He refactors it in four layers provided by Hanami View: (1) the **view** (Ruby object that decides which variables are exposed to the template); (2) **parts** (decorator Ruby classes that wrap exposed values, e.g. a RegistrationFormPart with an `errors(name)` method that always returns an array — no nils); (3) **scopes** (Ruby classes that compute the locals for a partial so templates don't have to — demoed with an `InputScope` that figures out `control_class_names`, `has_icons_right`, placeholder, label, input classes for a unified text_field partial); (4) **helpers** (plain helpers). Shows progressively extracting a field-icon partial, making the wrapper control class dynamic (to add `has_icons_right` only when an icon is present), passing errors generically, and finally hiding scope+render calls inside part decorator methods like `username_input(form_builder)` so the top-level template only calls decorator methods. All tooling is optional — you can use templates directly, add views, add parts, and add scopes only as complexity grows. Concludes that templating is hard, Hanami provides the most complete tooling on the web today, other projects (ViewComponent, Phlex) attack the same problem from different angles, and Rails developers shouldn't be scared to use non-Rails ideas in Rails apps. Q&A was empty aside from an audience joke about the speaker 'grilling Rails'.

date
2024-03-22
type
talk
talk Extracting logic from templates with Hanami Views
about
Hanami tool
Whole talk frames Hanami as a modular Rails alternative
talk Extracting logic from templates with Hanami Views
about
Main subject: the Hanami View gem (2.1) and its layers
talk Extracting logic from templates with Hanami Views
about
Demonstrates parts as decorators for exposed form values
talk Extracting logic from templates with Hanami Views
about
Demonstrates scopes computing locals for a unified text_field partial
talk Extracting logic from templates with Hanami Views
about
Contrasts Hanami with Rails' MVC, helpers, and all-or-nothing structure
talk Extracting logic from templates with Hanami Views
about
N+1 Queries concept
Cited as an example of issues nearly unique to the Rails ecosystem
talk Extracting logic from templates with Hanami Views
about
Talk critiques Rails' difficulty to disable or replace core components
talk Extracting logic from templates with Hanami Views
about
Service Object concept
Listed among community-invented Rails abstractions not backed by Rails philosophy
talk Extracting logic from templates with Hanami Views
about
Mentioned as another project attacking the view-logic extraction problem
talk Extracting logic from templates with Hanami Views
about
Phlex tool
Mentioned (as 'Flex') as another innovative view-logic solution
talk Extracting logic from templates with Hanami Views
about
Roda tool
Cited as the archetype of plugin-based modular Ruby frameworks
talk Extracting logic from templates with Hanami Views
about
AppSignal tool
Referenced as having dedicated UI for monitoring N+1 queries
authored
Extracting logic from templates with Hanami Views talk
Single speaker at wroclove.rb 2024
from_talk
Extracting logic from templates with Hanami Views talk
Derived from the parts/errors method example
from_talk
Extracting logic from templates with Hanami Views talk
Derived from the unified text_field partial refactor
from_talk
Extracting logic from templates with Hanami Views talk
Closing recommendation of the talk
talk Extracting logic from templates with Hanami Views
presented_at
Talk given at the 2024-03-22 wroclove.rb conference

Provenance

Created
2026-04-17 16:17 seed
Read by
24 extractions