From f04874f31c514fb66ef938c1b3b55a032a13845e Mon Sep 17 00:00:00 2001 From: David Kuhta Date: Tue, 23 Feb 2016 21:05:46 -0600 Subject: `stream_for` example --- guides/source/action_cable_overview.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'guides/source') diff --git a/guides/source/action_cable_overview.md b/guides/source/action_cable_overview.md index b18b3c3046..c24a507b9a 100644 --- a/guides/source/action_cable_overview.md +++ b/guides/source/action_cable_overview.md @@ -178,6 +178,21 @@ class ChatChannel < ApplicationCable::Channel end ``` +If you have a stream that is related to a model, then the broadcasting used +can be generated from the model and channel. The following example would +subscribe to a broadcasting like `comments:Z2lkOi8vVGVzdEFwcC9Qb3N0LzE` + +```ruby +class CommentsChannel < ApplicationCable::Channel + def subscribed + post = Post.find(params[:id]) + stream_for post + end +end +``` + You can then broadcast to this channel using: + `CommentsChannel.broadcast_to(@post, @comment)` + ### Broadcastings A broadcasting is a pub/sub link where anything transmitted by a publisher -- cgit v1.2.3