aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/action_cable_overview.md
diff options
context:
space:
mode:
authorDavid Kuhta <davidkuhta@gmail.com>2016-02-23 20:21:05 -0600
committerDavid Kuhta <davidkuhta@gmail.com>2016-02-23 20:21:05 -0600
commite39d8dd50692901d41baef52de909f67935248b6 (patch)
tree0dcdd217fb1d6f11c7653a909360a685d1d09ead /guides/source/action_cable_overview.md
parent55d9a70634aa2cb7f714b53561539ad42da8c9f3 (diff)
downloadrails-e39d8dd50692901d41baef52de909f67935248b6.tar.gz
rails-e39d8dd50692901d41baef52de909f67935248b6.tar.bz2
rails-e39d8dd50692901d41baef52de909f67935248b6.zip
Change ActionCable.server.broadcast to XChannel.broadcast_to
Using broadcast directly off server is not recommended
Diffstat (limited to 'guides/source/action_cable_overview.md')
-rw-r--r--guides/source/action_cable_overview.md17
1 files changed, 7 insertions, 10 deletions
diff --git a/guides/source/action_cable_overview.md b/guides/source/action_cable_overview.md
index 17c7f46562..26e07348f4 100644
--- a/guides/source/action_cable_overview.md
+++ b/guides/source/action_cable_overview.md
@@ -8,7 +8,7 @@ After reading this guide, you will know:
* How to setup Action Cable
* How to setup channels
-
+b
Introduction
------------
@@ -189,11 +189,10 @@ get the broadcast should they connect later.
Broadcasts are called elsewhere in your Rails application:
```ruby
-ActionCable.server.broadcast \
- "web_notifications_#{current_user.id}", { title: 'New things!', body: 'All the news that is fit to print' }
+ WebNotificationsChannel.broadcast_to current_user, title: 'New things!', body: 'All the news fit to print'
```
-The `ActionCable.server.broadcast` call places a message in the current
+The `WebNotificationsChannel.broadcast_to` call places a message in the current
subscription adapter (Redis by default)'s pubsub queue under a separate
broadcasting name for each user. For a user with an ID of 1, the broadcasting
name would be `web_notifications_1`.
@@ -267,8 +266,7 @@ App.cable.subscriptions.create { channel: "ChatChannel", room: "Best Room" },
```ruby
# Somewhere in your app this is called, perhaps from a NewCommentJob
-ActionCable.server.broadcast \
- "chat_#{room}", { sent_by: 'Paul', body: 'This is a cool chat app.' }
+ChatChannel.broadcast_to chat_#{room}, sent_by: 'Paul', body: 'This is a cool chat app.'
```
@@ -285,7 +283,7 @@ class ChatChannel < ApplicationCable::Channel
end
def receive(data)
- ActionCable.server.broadcast "chat_#{params[:room]}", data
+ ChatChannel.broadcast_to "chat_#{params[:room]}", data
end
end
```
@@ -430,11 +428,10 @@ App.cable.subscriptions.create "WebNotificationsChannel",
```ruby
# Somewhere in your app this is called, perhaps from a NewCommentJob
-ActionCable.server.broadcast \
- "web_notifications_#{current_user.id}", { title: 'New things!', body: 'All the news that is fit to print' }
+ WebNotificationsChannel.broadcast_to current_user, title: 'New things!', body: 'All the news fit to print'
```
-The `ActionCable.server.broadcast` call places a message in the current
+The `WebNotificationsChannel.broadcast_to` call places a message in the current
subscription adapter (Redis by default)'s pubsub queue under a separate
broadcasting name for each user. For a user with an ID of 1, the broadcasting
name would be `web_notifications_1`.