Turbo stream `broadcasts_to` from model does not find provided partial

I’m trying to set up my first turbo-stream broadcasts_to from a Comment model.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>class Comment < AbstractModel
belongs_to :target, polymorphic: true
belongs_to :user
after_create :notify_users
broadcasts_to(->(comment) { [comment.target, :comments] },
inserts_by: :prepend, partial: "comments/comment")
</code>
<code>class Comment < AbstractModel belongs_to :target, polymorphic: true belongs_to :user after_create :notify_users broadcasts_to(->(comment) { [comment.target, :comments] }, inserts_by: :prepend, partial: "comments/comment") </code>
class Comment < AbstractModel
  belongs_to :target, polymorphic: true
  belongs_to :user

  after_create :notify_users

  broadcasts_to(->(comment) { [comment.target, :comments] },
                inserts_by: :prepend, partial: "comments/comment")

On create, update or destroy, it’s not finding the partial supplied in the args.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Started PATCH "/comments/195463?q=1oNBT" for ::1 at 2024-05-10 10:39:20 -0700
Processing by CommentsController#update as TURBO_STREAM
[ActiveJob] Enqueued Turbo::Streams::ActionBroadcastJob (Job ID: e1c46c84-d13c-4562-a2c1-9b9ea85b7a22) to SolidQueue(default) with arguments: "Z2lkOi8vbXVzaHJvb20tb2JzZXJ2ZXIvT2JzZXJ2YXRpb24vNTE1NzEz:comments", {:action=>:replace, :target=>#<GlobalID:0x0000000118d8b468 @uri=#<URI::GID gid://mushroom-observer/Comment/195463>>, :targets=>nil, :attributes=>{}, :partial=>"comments/comment", :locals=>{:comment=>#<GlobalID:0x0000000118d8b058 @uri=#<URI::GID gid://mushroom-observer/Comment/195463>>, :request_id=>"6909dbb3-b936-4ab9-b4e6-89392e62d7c5"}}
No template found for CommentsController#update, rendering head :no_content
</code>
<code>Started PATCH "/comments/195463?q=1oNBT" for ::1 at 2024-05-10 10:39:20 -0700 Processing by CommentsController#update as TURBO_STREAM [ActiveJob] Enqueued Turbo::Streams::ActionBroadcastJob (Job ID: e1c46c84-d13c-4562-a2c1-9b9ea85b7a22) to SolidQueue(default) with arguments: "Z2lkOi8vbXVzaHJvb20tb2JzZXJ2ZXIvT2JzZXJ2YXRpb24vNTE1NzEz:comments", {:action=>:replace, :target=>#<GlobalID:0x0000000118d8b468 @uri=#<URI::GID gid://mushroom-observer/Comment/195463>>, :targets=>nil, :attributes=>{}, :partial=>"comments/comment", :locals=>{:comment=>#<GlobalID:0x0000000118d8b058 @uri=#<URI::GID gid://mushroom-observer/Comment/195463>>, :request_id=>"6909dbb3-b936-4ab9-b4e6-89392e62d7c5"}} No template found for CommentsController#update, rendering head :no_content </code>
Started PATCH "/comments/195463?q=1oNBT" for ::1 at 2024-05-10 10:39:20 -0700
Processing by CommentsController#update as TURBO_STREAM
[ActiveJob] Enqueued Turbo::Streams::ActionBroadcastJob (Job ID: e1c46c84-d13c-4562-a2c1-9b9ea85b7a22) to SolidQueue(default) with arguments: "Z2lkOi8vbXVzaHJvb20tb2JzZXJ2ZXIvT2JzZXJ2YXRpb24vNTE1NzEz:comments", {:action=>:replace, :target=>#<GlobalID:0x0000000118d8b468 @uri=#<URI::GID gid://mushroom-observer/Comment/195463>>, :targets=>nil, :attributes=>{}, :partial=>"comments/comment", :locals=>{:comment=>#<GlobalID:0x0000000118d8b058 @uri=#<URI::GID gid://mushroom-observer/Comment/195463>>, :request_id=>"6909dbb3-b936-4ab9-b4e6-89392e62d7c5"}}
No template found for CommentsController#update, rendering head :no_content

Why not? The partial is in comments/comment.erb.

My understanding is that with broadcasts_to and a partial arg, I should not supply turbo_stream responses in the controller, Rails will figure it out.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code># comments_controller.rb
def update
# ...update the comment if validated, then:
respond_to do |format|
format.turbo_stream # do
# render(
# turbo_stream: turbo_stream.prepend(
# :comments, partial: "comments/comment", locals: { comment: @comment }
# )
# )
# end
format.html do
redirect_to(@target)
end
end
end
</code>
<code># comments_controller.rb def update # ...update the comment if validated, then: respond_to do |format| format.turbo_stream # do # render( # turbo_stream: turbo_stream.prepend( # :comments, partial: "comments/comment", locals: { comment: @comment } # ) # ) # end format.html do redirect_to(@target) end end end </code>
# comments_controller.rb

def update
  # ...update the comment if validated, then:
  respond_to do |format|
    format.turbo_stream # do
      # render(
      #   turbo_stream: turbo_stream.prepend(
      #     :comments, partial: "comments/comment", locals: { comment: @comment }
      #   )
      # )
    # end
    format.html do
      redirect_to(@target)
    end
  end
end

If i do render turbo_stream in the controller response, the comment updates for the current user, but does not stream to other users, even though the turbo-cable-stream-source is connected on both browsers.

The view partial is streaming from the correct stream, I believe:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><%= turbo_stream_from([target, :comments], :comments) %>
</code>
<code><%= turbo_stream_from([target, :comments], :comments) %> </code>
<%= turbo_stream_from([target, :comments], :comments) %>

This is a mature Rails 7.1.3/Ruby 3.3.0 app where Turbo, Stimulus, importmaps, and SolidQueue are already running ok. I’ve added redis for ActionCable and i’m running a puma server in dev. Everything seems ok with the websocket connection and ActiveJob.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code># cable.yml
development:
adapter: redis
url: redis://localhost:6379/1
</code>
<code># cable.yml development: adapter: redis url: redis://localhost:6379/1 </code>
# cable.yml
development:
  adapter: redis
  url: redis://localhost:6379/1

What am I missing?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật