Browse Source

render notice

main
pvincent 2 months ago
parent
commit
6af3df71e7
  1. 2
      app/assets/stylesheets/tailwind/main.tailwind.css
  2. 14
      app/controllers/flash_controller.rb
  3. 5
      app/views/flash/index.html.erb
  4. 1
      config/routes.rb

2
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}

14
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]}"

5
app/views/flash/index.html.erb

@ -7,9 +7,10 @@
<li>
<%= link_to 'redirect with flash alert', flash_redirect_with_alert_path, class: :button %>
</li>
<li>
<%= link_to 'render notice', flash_render_notice_path, class: :button %>
</li>
<li>
<%= link_to 'turbo notice', flash_turbo_notice_path, class: :button, 'data-turbo-method': :post %>
</li>
<li></li>
<li></li>
</ul>

1
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

Loading…
Cancel
Save