Skip to content

Commit 5973298

Browse files
committed
broadcast quote creation and display
1 parent fe7b4dc commit 5973298

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

app/models/quote.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@ class Quote < ApplicationRecord
22
validates :name, presence: true
33

44
scope :desc_id_ordered, -> { order(id: :desc) }
5+
6+
# QUESTIONS:
7+
# - how to limit access / specify policy for channels?
8+
# - how to test
9+
# after_create_commit -> { broadcast_prepend_to "quotes", target: "quotes", partial: "quotes/quote", locals: { quote: self } }
10+
after_create_commit -> { broadcast_prepend_to "quotes" }
511
end

app/views/quotes/index.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ COMMENT
2828
data: { turbo_frame: dom_id(Quote.new) } %>
2929
</div>
3030

31+
<%= turbo_stream_from "quotes" %>
3132
<%= turbo_frame_tag Quote.new %>
3233
<%= turbo_frame_tag "quotes" do %>
3334
<%= render @quotes %>

0 commit comments

Comments
 (0)