aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorDavid Kuhta <davidkuhta@gmail.com>2016-02-23 21:05:46 -0600
committerDavid Kuhta <davidkuhta@gmail.com>2016-02-23 21:05:46 -0600
commitf04874f31c514fb66ef938c1b3b55a032a13845e (patch)
tree02f4c116002f946a32d0616bb9e69e933fb28608 /guides
parenta946f3930b2d9f4a69e8ce81beb9f3bbed7fd764 (diff)
downloadrails-f04874f31c514fb66ef938c1b3b55a032a13845e.tar.gz
rails-f04874f31c514fb66ef938c1b3b55a032a13845e.tar.bz2
rails-f04874f31c514fb66ef938c1b3b55a032a13845e.zip
`stream_for` example
Diffstat (limited to 'guides')
-rw-r--r--guides/source/action_cable_overview.md15
1 files changed, 15 insertions, 0 deletions
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