Does it vary from case to case?
I’ve seen:
model broadcasts
class Post < ApplicationRecord
broadcasts_to ->(post) { :posts }
# or
after_create_commit do
broadcast_update_to :posts, target: 'posts_count', partial: "posts/count", locals: { count: Post.count }
end
end
controller broadcasts
class CountersController < ApplicationController
def increment
@counter.increment
respond_to do |format|
format.turbo_stream do
render turbo_stream: turbo_stream.update(@counter),
partial: 'counters/counter_value',
locals: { counter: @counter }
end
end
end
end
or
format.turbo_stream
with separate views similar to the old format.script
… new.js.erb
<%= turbo_stream.update @counter, "counters/counter" locals: {counter: @counter} %>