diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ea42dc2..a5f1171 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,9 +3,7 @@ class ApplicationController < ActionController::Base allow_browser versions: :modern def render_stream(notice: nil, alert: nil, &) - flash.now[:notice] = notice if notice - flash.now[:alert] = alert if alert - + flash_now_only!(notice, alert) proxy_stream = ProxyStream.new(turbo_stream) proxy_stream.replace(:flash, partial: 'layouts/components/flash') if flash.any? yield(proxy_stream) if block_given? @@ -29,4 +27,12 @@ class ApplicationController < ActionController::Base end end private_constant(:ProxyStream) + + private + + def flash_now_only!(notice, alert) + flash.discard + flash.now[:notice] = notice if notice + flash.now[:alert] = alert if alert + end end