I have a new Rails 8.0.1 app
In an index.html.erb page I code:
<%= turbo_stream_from "test" %>
<div id="message">
<p>hello</p>
</div>
In server output everything seams ok:
08:58:49 web.1 | Started GET "/cable" for 127.0.0.1 at 2025-01-14 08:58:49 +0000
08:58:49 web.1 | Started GET "/cable" [WebSocket] for 127.0.0.1 at 2025-01-14 08:58:49 +0000
08:58:49 web.1 | Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
08:58:49 web.1 | Turbo::StreamsChannel is transmitting the subscription confirmation
08:58:49 web.1 | Turbo::StreamsChannel is streaming from test
Now I open a console and write:
Turbo::StreamsChannel.broadcast_replace_to(
"test",
target: "message",
html: "<p>bye</p>"
)
output:
[ActionCable] Broadcasting to test: "<turbo-stream action=\"replace\" target=\"message\"><template><p>bye</p></template></turbo-stream>"
Nothing happen in the browser. I checked in devtools network the websocket connection "cable":
Request URL: ws://localhost:3000/cable
Request Method: GET
Status Code: 101 Switching Protocols
and in messages, the three first, and after that the pings:
{"type":"welcome"}
{"command":"subscribe","identifier":"{\"channel\":\"Turbo::StreamsChannel\",\"signed_stream_name\":\"InRlc3Qi--b4e0cf48724894bdbc04aecdb38b58f60f628af8d3e16fc2d7c552cfe0e98d5c\"}"}
{"identifier":"{\"channel\":\"Turbo::StreamsChannel\",\"signed_stream_name\":\"InRlc3Qi--b4e0cf48724894bdbc04aecdb38b58f60f628af8d3e16fc2d7c552cfe0e98d5c\"}","type":"confirm_subscription"}
but nothing happen in the server.
Thanks in advance
The default Async adapter does not support broadcasting. To enable broadcasting, I need to configure a persistent adapter like Redis for Action Cable.