Module: Controllers::TurboStreamFlashable

Extended by:
ActiveSupport::Concern
Included in:
ApplicationController, Auth::CustomerSessionsController
Defined in:
app/concerns/controllers/turbo_stream_flashable.rb

Overview

TurboStreamFlashable automatically handles flash messages for Turbo Stream responses.

This concern uses an after_action callback to detect when:

  1. The response format is turbo_stream
  2. A response body has been rendered

Subdomain-specific behavior:

  • WWW: Shows flash messages as Bootstrap Toasts via turbo_stream.toast
  • CRM: Updates #notice_area with Callout-style messages

When flash messages are present, it automatically:

  • Converts flash messages to flash.now (preventing double display)
  • Appends the appropriate flash partial to the turbo_stream response

Usage in controllers:

Just set flash normally - it will be automatically handled!

flash[:info] = 'Post was successfully created.'
flash[:error] = 'Something went wrong.'

respond_to do |format|
format.html { redirect_to @post }
format.turbo_stream { render turbo_stream: [] } # Flash will be automatically appended
end

IMPORTANT: You must render something for turbo_stream (even an empty array)
so the after_action has a response body to append the flash to. Without this,
Rails will look for a template and may trigger a 404 error.

You can also use flash.now directly if you prefer:
flash.now[:info] = 'Message'