Skip to content

Instantly share code, notes, and snippets.

@oliveira-andre
Last active April 10, 2025 14:57
Show Gist options
  • Save oliveira-andre/9369236aa59cc8ccdefb37e2aab2fcfd to your computer and use it in GitHub Desktop.
Save oliveira-andre/9369236aa59cc8ccdefb37e2aab2fcfd to your computer and use it in GitHub Desktop.
Websocket Real-Time Messages Rails 8+

Websocket Real Time messages

on your rails app 8+ include this turbo_stream_from it will open a websocket subscription with action cable

<%= turbo_stream_from :todos %>

Sending custom messages manually with action cable

ActionCable.server.broadcast "todos", "Hello"

Or with turbo frames

ActionCable.server.broadcast "todos", "<turbo-frame action='append' target='todos'><template>Hello</template></turbo-frame>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment