<%# views/messages/create.turbo_stream.erb %>
<%= turbo_stream.append "messages" do %>
<%= render @message %>
<% end %>
<%# views/messages/_message.html.erb %>
<%-
klass =
if current_user&.id
= =
message.user_id
"mine"
else
"theirs"
end
-%>
<%= message.content %>
div>
# models/channel.rb
class Message < ApplicationRecord
belongs_to :channel, touch: true
belongs_to :user
after_commit on: :create do
broadcast_append_to(
channel,
partial: "messages/message",
locals: {
message: self,
current_user: nil
},
target: "messages"
)
end
end
Stub current user