Lesson 6 — The complete boards controller, destroy, and flash
The complete controller
|
|
We’ll need an Edit button and a Destroy button. Update your Views::Boards::Show page
with the following:
|
|
Turbo intercepts the form and shows a native confirmation dialog before sending the DELETE request. No JavaScript needed.
Model validations
|
|
Flash messages in the layout
Update AppLayout to render flash messages using Alert:
|
|
Call render_flash from view_template between render_nav and main.
Flash messages are functional but have limitations — they persist until navigation and shift the page layout. In Module 8 we replace them with Toast notifications that auto-dismiss and float over the UI without affecting layout.
Module 6 summary
form_withworks in Phlex viainclude Phlex::Rails::Helpers::FormWithinComponents::Base— CSRF is automatic, HTTP method and URL are inferred from model persistence- Use
button(type: "submit")rather thanf.submitfor submit buttons — it accepts a content block and is consistent with theButtoncomponent FormFieldis the base class for all input primitives — it owns the shared props (field,label,hint,error,required) and the label/hint rendering. Subclasses only implementrender_input- Each primitive owns its label — pass
label: "Field name"and the label renders with the correctforattribute automatically. Nolabel:prop means no label rendered - All primitives accept
error: truefor red styling andaria-invalid="true"— error message display is the form’s responsibility, not the primitive’s - Three error handling strategies — summary at top, inline per field, or both — choose based on form size and audience
BoardFormlives underViews::notComponents::— it is app-specific, knows aboutBoard, and is not a portable library component- Self-permitting forms —
PERMITTEDon the form class, called viaparams.expect(board: FormClass.permitted)in the controller — eliminates hand-written permit lists - Destroy needs no view —
form_with(method: :delete)withdata: { turbo_confirm: }handles it with Turbo’s confirmation dialog - All Tailwind classes in this module use raw palette values — semantic tokens are introduced in Module 7
Components built this module
Components::FormField— base class for all form primitivesComponents::TextInputComponents::TextareaComponents::SelectComponents::CheckboxComponents::RadioComponents::NumberInputComponents::HiddenInputComponents::ErrorSummary
Views built this module
Views::Boards::BoardFormViews::Boards::NewViews::Boards::Edit
KanbanFlow progress
KanbanFlow now has a fully working board management UI — create, view,
edit, and delete boards. Validation errors display inline with accessible
ARIA attributes. Flash messages appear in the layout via Alert. The
controller never hand-writes a permit list.