mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Tune whitespace in README.md
* Realign `end` statements with the opening `class` statement. * Pad JavaScript objects with spaces to match Rails styleguide and for consistency with other examples.
This commit is contained in:
parent
63cdbf87dd
commit
6be2604aa7
1 changed files with 5 additions and 5 deletions
10
README.md
10
README.md
|
@ -187,7 +187,7 @@ class WebNotificationsChannel < ApplicationCable::Channel
|
|||
def subscribed
|
||||
stream_from "web_notifications_#{current_user.id}"
|
||||
end
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
```coffeescript
|
||||
|
@ -219,14 +219,14 @@ class ChatChannel < ApplicationCable::Channel
|
|||
def subscribed
|
||||
stream_from "chat_#{params[:room]}"
|
||||
end
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
Pass an object as the first argument to `subscriptions.create`, and that object will become your params hash in your cable channel. The keyword `channel` is required.
|
||||
|
||||
```coffeescript
|
||||
# Client-side which assumes you've already requested the right to send web notifications
|
||||
App.cable.subscriptions.create {channel: "ChatChannel", room: "Best Room"},
|
||||
App.cable.subscriptions.create { channel: "ChatChannel", room: "Best Room" },
|
||||
received: (data) ->
|
||||
new Message data['sent_by'], body: data['body']
|
||||
```
|
||||
|
@ -257,11 +257,11 @@ end
|
|||
|
||||
```coffeescript
|
||||
# Client-side which assumes you've already requested the right to send web notifications
|
||||
sub = App.cable.subscriptions.create {channel: "ChatChannel", room: "Best Room"},
|
||||
sub = App.cable.subscriptions.create { channel: "ChatChannel", room: "Best Room" },
|
||||
received: (data) ->
|
||||
new Message data['sent_by'], body: data['body']
|
||||
|
||||
sub.send {sent_by: 'Peter', body: 'Hello Paul, thanks for the compliment.'}
|
||||
sub.send { sent_by: 'Peter', body: 'Hello Paul, thanks for the compliment.' }
|
||||
```
|
||||
|
||||
The rebroadcast will be received by all connected clients, _including_ the client that sent the message. Note that params are the same as they were when you subscribed to the channel.
|
||||
|
|
Loading…
Reference in a new issue