Skip to content

Commit 9d613e5

Browse files
newstlerclaude
andcommitted
fix(message): render messages/_message partial in broadcasts
RubyLLM 1.14.1 added a `to_partial_path` override returning "messages/<role>" (user/assistant/system/tool). With the bump from 1.11.0 in #102, turbo-rails' `broadcasts_to` stopped finding a partial because the app only has a single role-aware `_message.html.erb`. Every message save crashed Turbo::Streams::ActionBroadcastJob with ActionView::MissingTemplate, silently breaking live chat UI updates for subscribers (real chats, summaries, testimonials, translations). Pin the broadcast partial explicitly. Added a regression test that saves a Message with every role and asserts the enqueued broadcast job renders cleanly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6a04042 commit 9d613e5

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

app/models/message.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class Message < ApplicationRecord
22
acts_as_message tool_calls_foreign_key: :message_id
33
has_many_attached :attachments
4-
broadcasts_to ->(message) { "chat_#{message.chat_id}" }, inserts_by: :append, target: "messages"
4+
broadcasts_to ->(message) { "chat_#{message.chat_id}" }, inserts_by: :append, target: "messages", partial: "messages/message"
55

66
after_update_commit :broadcast_message_replacement, if: :assistant?
77
before_save :calculate_cost, if: :should_calculate_cost?

test/models/message_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
require "test_helper"
22

33
class MessageTest < ActiveSupport::TestCase
4+
include ActiveJob::TestHelper
5+
46
test "calculates cost based on token usage" do
57
message = Message.new(
68
chat: chats(:one),
@@ -15,4 +17,14 @@ class MessageTest < ActiveSupport::TestCase
1517

1618
assert message.cost > 0
1719
end
20+
21+
test "broadcasts create using messages/message partial regardless of role" do
22+
%w[user assistant system tool].each do |role|
23+
message = Message.new(chat: chats(:one), role: role, content: "hi")
24+
25+
assert_nothing_raised do
26+
perform_enqueued_jobs { message.save! }
27+
end
28+
end
29+
end
1830
end

0 commit comments

Comments
 (0)