0

I've been trying to get turbo_stream_from working, without any luck. Something seems to be broadcasting, but it doesn't update the view, nor do I see any logs like "Turbo::StreamsChannel is transmitting" from my rails server.

# show.html.erb

<%= turbo_stream_from "content_ideas" %>
<div id="<%= dom_id(@content_idea) %>">
  <%= render @content_idea %> 
</div>
# content_idea.rb

class ContentIdea < ApplicationRecord
  belongs_to :ig_account
  belongs_to :content_idea, optional: true
  has_many :content_ideas

  enum status: %i[fresh generating used saved rejected]
  after_update_commit -> { broadcast_update_to "content_ideas", partial: "content_ideas/content_idea", locals: { content_idea: self }, target: "content_idea_#{self.id}" }
end
# content_ideas/_content_idea.html.erb

<%= content_idea.status %>
# rails console

:009 > content_idea = ci
 => #<ContentIdea id: 26, content: "Share a series of Instagram stories or a carousel ...", ig_account_id: 9510, status: "used", purpos... 
 :010 > content_idea.touch
  TRANSACTION (0.2ms)  BEGIN
  ContentIdea Update (0.5ms)  UPDATE "content_ideas" SET "updated_at" = $1 WHERE "content_ideas"."id" = $2  [["updated_at", "2023-05-11 04:15:51.814170"], ["id", 26]]
  TRANSACTION (0.8ms)  COMMIT
  Rendered content_ideas/_content_idea.html.erb (Duration: 0.0ms | Allocations: 7)
[ActionCable] Broadcasting to content_ideas: "<turbo-stream action=\"update\" target=\"content_idea_26\"><template>used\n</template></turbo-stream>"
 => true 
# rails server

Completed 200 OK in 259ms (Views: 157.9ms | ActiveRecord: 50.6ms | Allocations: 98873)


Started GET "/cable" for ::1 at 2023-05-10 21:12:22 -0700
Started GET "/cable/" [WebSocket] for ::1 at 2023-05-10 21:12:22 -0700
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
Started GET "/cable" for ::1 at 2023-05-10 21:12:23 -0700
Started GET "/cable/" [WebSocket] for ::1 at 2023-05-10 21:12:23 -0700
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
Started GET "/cable" for ::1 at 2023-05-10 21:12:29 -0700
Started GET "/cable/" [WebSocket] for ::1 at 2023-05-10 21:12:29 -0700
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)

In similar questions I've seen people's servers returning messaging like this, which I seem to be missing:

12:24:55 web.1    | Turbo::StreamsChannel is transmitting the subscription confirmation
12:24:55 web.1    | Turbo::StreamsChannel is streaming from documents 

I also noticed that content_idea.broadcast_update in IRB return 0, whereas youtube tutorials show this returning 1:

 :012 > content_idea.broadcast_update
  Rendered content_ideas/_content_idea.html.erb (Duration: 0.1ms | Allocations: 7)
[ActionCable] Broadcasting to Z2lkOi8vaGFzaHRhZy1zbGF5ZXIvQ29udGVudElkZWEvMjY: "<turbo-stream action=\"update\" target=\"content_idea_26\"><template>used\n</template></turbo-stream>"
 => 0 

I've restarted my server countless times. This project was also recently upgraded from Rails 6 to 7.0.0.

Lastly, is the network table supposed to look like this on the view? Screenshot

Gantrof
  • 31
  • 9

0 Answers0