Browse Source

fix button_to instead of link_to

main
pvincent 5 days ago
parent
commit
773887e870
  1. 1
      app/controllers/application_controller.rb
  2. 8
      app/controllers/notification_controller.rb
  3. 6
      app/views/notification/index.html.erb
  4. 8
      config/routes.rb

1
app/controllers/application_controller.rb

@ -7,6 +7,7 @@ class ApplicationController < ActionController::Base
flash.now[:alert] = alert if alert flash.now[:alert] = alert if alert
streams = [] streams = []
streams << turbo_stream.replace(:flash, partial: 'layouts/components/flash') if flash.any? streams << turbo_stream.replace(:flash, partial: 'layouts/components/flash') if flash.any?
# TODO: turbo_stream_elements which stores any append, prepend, replace, update, remove, before, after or refresh actions
if block_given? if block_given?
yields = yield(turbo_stream) yields = yield(turbo_stream)
if yields.is_a? Array if yields.is_a? Array

8
app/controllers/notification_controller.rb

@ -27,10 +27,10 @@ class NotificationController < ApplicationController
flash.now[:alert] = "alert, do the stuff right now ##{inc_count}" flash.now[:alert] = "alert, do the stuff right now ##{inc_count}"
flash.now[:notice] = ["this is extra notice ##{inc_count}", 'one more time'] flash.now[:notice] = ["this is extra notice ##{inc_count}", 'one more time']
render_stream do |stream| render_stream do |stream|
[
stream.replace(:turbo_placeholder, partial: 'turbo_placeholder'),
stream.replace(:turbo_placeholder2, partial: 'turbo_placeholder2')
]
# TODO: turbo_stream_elements which stores any append, prepend, replace, update, remove, before, after or refresh actions
stream.replace(:turbo_placeholder, partial: 'turbo_placeholder')
stream.replace(:turbo_placeholder2, partial: 'turbo_placeholder2')
end end
end end

6
app/views/notification/index.html.erb

@ -37,17 +37,17 @@
<ul class="flex flex-row list bg-base-100 rounded-box shadow-md"> <ul class="flex flex-row list bg-base-100 rounded-box shadow-md">
<li class="p-4 pb-2 text-xs opacity-60 tracking-wide"> <li class="p-4 pb-2 text-xs opacity-60 tracking-wide">
<%= link_to notification_turbo_notice_path, class: "btn btn-primary", data: { turbo_stream: true, turbo_prefetch: false } do %>
<%= button_to notification_turbo_notice_path, class: "btn btn-primary", data: { turbo_stream: true, turbo_prefetch: false } do %>
Turbo Notice Turbo Notice
<% end %> <% end %>
</li> </li>
<li class="p-4 pb-2 text-xs opacity-60 tracking-wide"> <li class="p-4 pb-2 text-xs opacity-60 tracking-wide">
<%= link_to notification_turbo_alert_path, class: "btn btn-secondary", data: { turbo_stream: true, turbo_prefetch: false } do %>
<%= button_to notification_turbo_alert_path, class: "btn btn-secondary", data: { turbo_stream: true, turbo_prefetch: false } do %>
Turbo Alert Turbo Alert
<% end %> <% end %>
</li> </li>
<li class="p-4 pb-2 text-xs opacity-60 tracking-wide"> <li class="p-4 pb-2 text-xs opacity-60 tracking-wide">
<%= link_to notification_turbo_more_path, class: "btn btn-accent",
<%= button_to notification_turbo_more_path, class: "btn btn-accent",
data: { turbo_stream: true, turbo_prefetch: false } do %> data: { turbo_stream: true, turbo_prefetch: false } do %>
Turbo More Turbo More
<% end %> <% end %>

8
config/routes.rb

@ -3,8 +3,8 @@ Rails.application.routes.draw do
get 'notification/index' get 'notification/index'
get 'notification/show_notice' get 'notification/show_notice'
get 'notification/show_alert' get 'notification/show_alert'
get 'notification/turbo_notice'
get 'notification/turbo_alert'
get 'notification/turbo_more'
get 'notification/turbo_none'
post 'notification/turbo_notice'
post 'notification/turbo_alert'
post 'notification/turbo_more'
post 'notification/turbo_none'
end end
Loading…
Cancel
Save