From 6af3df71e73b5e2a561242354b9435ad13f43ba4 Mon Sep 17 00:00:00 2001 From: pvincent Date: Wed, 10 Jul 2024 02:29:17 +0400 Subject: [PATCH] render notice --- app/assets/stylesheets/tailwind/main.tailwind.css | 2 +- app/controllers/flash_controller.rb | 14 ++++++++++++-- app/views/flash/index.html.erb | 5 +++-- config/routes.rb | 1 + 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/assets/stylesheets/tailwind/main.tailwind.css b/app/assets/stylesheets/tailwind/main.tailwind.css index 8518303..0ae0423 100644 --- a/app/assets/stylesheets/tailwind/main.tailwind.css +++ b/app/assets/stylesheets/tailwind/main.tailwind.css @@ -14,5 +14,5 @@ h5 { @apply text-xl} h6 { @apply text-base } .title { @apply bg-gradient-to-r from-color-primary to-color-secondary text-yellow-400 sm:rounded-t-lg; } -.button { @apply bg-slate-200 hover:bg-slate-500 cursor-pointer } +.button { @apply bg-slate-200 hover:bg-slate-400 px-1 cursor-pointer } .menu { @apply text-slate-200 hover:bg-slate-700 p-2 text-2xl} \ No newline at end of file diff --git a/app/controllers/flash_controller.rb b/app/controllers/flash_controller.rb index 9cbe6cc..9f309f8 100644 --- a/app/controllers/flash_controller.rb +++ b/app/controllers/flash_controller.rb @@ -1,8 +1,15 @@ # interaction with the flash message class FlashController < ApplicationController def index; end - def redirect_with_notice = redirect_to flash_path, notice: build_message(:notice) - def redirect_with_alert = redirect_to flash_path, alert: build_message(:alert) + + def redirect_with_notice = redirect_to(flash_path, notice:) + def redirect_with_alert = redirect_to(flash_path, alert:) + + def render_notice + flash[:notice] = 'From Render' + flash[:alert] = 'Alert Render' + render :index + end def turbo_notice flash[:notice] = 'From Turbo' @@ -12,6 +19,9 @@ class FlashController < ApplicationController private + def notice = build_message(:notice) + def alert = build_message(:alert) + def build_message(type_of_message) session[:flash_iteration] = session[:flash_iteration].to_i + 1 "this is #{type_of_message} ##{session[:flash_iteration]}" diff --git a/app/views/flash/index.html.erb b/app/views/flash/index.html.erb index 1b3a07c..8c2e3bc 100644 --- a/app/views/flash/index.html.erb +++ b/app/views/flash/index.html.erb @@ -7,9 +7,10 @@
  • <%= link_to 'redirect with flash alert', flash_redirect_with_alert_path, class: :button %>
  • +
  • + <%= link_to 'render notice', flash_render_notice_path, class: :button %> +
  • <%= link_to 'turbo notice', flash_turbo_notice_path, class: :button, 'data-turbo-method': :post %>
  • -
  • -
  • \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index a45715e..e26e58e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,6 +10,7 @@ Rails.application.routes.draw do root 'scores#index' get 'flash' => 'flash#index' + get 'flash/render_notice' => 'flash#render_notice', as: :flash_render_notice get 'flash/redirect_with_notice' => 'flash#redirect_with_notice', as: :flash_redirect_with_notice get 'flash/redirect_with_alert' => 'flash#redirect_with_alert', as: :flash_redirect_with_alert post 'flash/turbo_notice' => 'flash#turbo_notice', as: :flash_turbo_notice