From c57fe587c2582923861f5433cd3967f4f51317c7 Mon Sep 17 00:00:00 2001 From: Trevor Vallender Date: Fri, 18 Aug 2023 21:02:39 +0100 Subject: [PATCH] Use helper to update flash in streams --- app/helpers/application_helper.rb | 6 ++++++ app/views/sessions/new.turbo_stream.erb | 5 ++--- app/views/users/edit.turbo_stream.erb | 5 ++--- app/views/users/new.turbo_stream.erb | 5 ++--- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 3e71ce8..a6c8304 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -8,4 +8,10 @@ module ApplicationHelper def current_user @current_user ||= User.find(session[:user_id]) if logged_in? end + + def update_flash + turbo_stream.replace "flash_wrapper" do + render "shared/flash" + end + end end diff --git a/app/views/sessions/new.turbo_stream.erb b/app/views/sessions/new.turbo_stream.erb index 1c664a1..9ed1f2b 100644 --- a/app/views/sessions/new.turbo_stream.erb +++ b/app/views/sessions/new.turbo_stream.erb @@ -1,7 +1,6 @@ <% @title = "Log in" %> -<%= turbo_stream.replace "flash_wrapper" do %> - <%= render "shared/flash" %> -<% end %> + +<%= update_flash %> <%= turbo_stream.replace "session_form" do %> <%= form_with url: sessions_path, method: :post, id: "session_form" do |f| %> diff --git a/app/views/users/edit.turbo_stream.erb b/app/views/users/edit.turbo_stream.erb index 0078c8c..f8bee01 100644 --- a/app/views/users/edit.turbo_stream.erb +++ b/app/views/users/edit.turbo_stream.erb @@ -1,7 +1,6 @@ <% @title = "Edit account details" %> -<%= turbo_stream.replace "flash_wrapper" do %> - <%= render "shared/flash" %> -<% end %> + +<%= update_flash %> <%= turbo_stream.replace "user_form" do %> <%= render partial: "form", diff --git a/app/views/users/new.turbo_stream.erb b/app/views/users/new.turbo_stream.erb index 9897573..e01451a 100644 --- a/app/views/users/new.turbo_stream.erb +++ b/app/views/users/new.turbo_stream.erb @@ -1,7 +1,6 @@ <% @title = "Register" %> -<%= turbo_stream.replace "flash_wrapper" do %> - <%= render "shared/flash" %> -<% end %> + +<%= update_flash %> <%= turbo_stream.replace "user_form" do %> <%= render partial: "form",