You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1019 B

4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
  1. # interaction with the flash message
  2. class FlashController < ApplicationController
  3. def index; end
  4. def redirect_with_notice = redirect_to(flash_path, notice:)
  5. def redirect_with_alert = redirect_to(flash_path, alert:)
  6. def redirect_with_both
  7. flash[:notice] = notice
  8. flash[:alert] = alert
  9. redirect_to flash_path
  10. end
  11. def from_render
  12. session[:flash_iteration] = session[:flash_iteration].to_i + 1
  13. flash.now[:notice] = "From Render #{session[:flash_iteration]}"
  14. flash.now[:alert] = "Alert Render #{session[:flash_iteration]}"
  15. logger.info(flash.object_id)
  16. render :index
  17. end
  18. def from_turbo
  19. flash.now[:notice] = 'From Turbo'
  20. flash.now[:alert] = 'Alert Turbo'
  21. render turbo_stream: flash_stream
  22. end
  23. private
  24. def notice = build_message(:notice)
  25. def alert = build_message(:alert)
  26. def build_message(type_of_message)
  27. session[:flash_iteration] = session[:flash_iteration].to_i + 1
  28. "this is #{type_of_message} ##{session[:flash_iteration]}"
  29. end
  30. end