Turbo Stream flash messages without custom JS

743
0

Instead of sprinkling custom JS for notifications, I treat flash as UI state and render it via Turbo Streams. When a create/update succeeds, the controller responds to format.turbo_stream and the template uses turbo_stream.replace to swap the flash container. This keeps the behavior consistent for normal HTML requests and Turbo visits, and it also avoids the common bug where flash only appears after a redirect. I like to keep the flash DOM stable with a single #flash wrapper and let the server decide content. It’s straightforward to extend with different levels (notice, alert) and auto-dismiss later via Stimulus.