aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md41
1 files changed, 31 insertions, 10 deletions
diff --git a/README.md b/README.md
index 5c6cb1c0fe..ebc505db19 100644
--- a/README.md
+++ b/README.md
@@ -54,7 +54,7 @@ module ApplicationCable
protected
def find_verified_user
- if current_user = User.find(cookies.signed[:user_id])
+ if current_user = User.find_by(id: cookies.signed[:user_id])
current_user
else
reject_unauthorized_connection
@@ -162,7 +162,7 @@ $(document).on 'click', '[data-behavior~=appear_away]', ->
```
Simply calling `App.cable.subscriptions.create` will setup the subscription, which will call `AppearanceChannel#subscribed`,
-which in turn is linked to original `App.consumer` -> `ApplicationCable::Connection` instances.
+which in turn is linked to original `App.cable` -> `ApplicationCable::Connection` instances.
We then link `App.appearance#appear` to `AppearanceChannel#appear(data)`. This is possible because the server-side
channel instance will automatically expose the public methods declared on the class (minus the callbacks), so that these
@@ -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.
@@ -274,8 +274,11 @@ See the [rails/actioncable-examples](http://github.com/rails/actioncable-example
## Configuration
-The only must-configure part of Action Cable is the Redis connection. By default, `ActionCable::Server::Base` will look for a configuration
-file in `Rails.root.join('config/redis/cable.yml')`. The file must follow the following format:
+Action Cable has two required configurations: the Redis connection and specifying allowed request origins.
+
+### Redis
+
+By default, `ActionCable::Server::Base` will look for a configuration file in `Rails.root.join('config/redis/cable.yml')`. The file must follow the following format:
```yaml
production: &production
@@ -299,6 +302,24 @@ a Rails initializer with something like:
ActionCable.server.config.redis_path = Rails.root('somewhere/else/cable.yml')
```
+### Allowed Request Origins
+
+Action Cable will only accepting requests from specified origins, which are passed to the server config as an array:
+
+```ruby
+ActionCable.server.config.allowed_request_origins = %w( http://rubyonrails.com )
+```
+
+To disable and allow requests from any origin:
+
+```ruby
+ActionCable.server.config.disable_request_forgery_protection = true
+```
+
+By default, Action Cable allows all requests from localhost:3000 when running in the development environment.
+
+### Other Configurations
+
The other common option to configure is the log tags applied to the per-connection logger. Here's close to what we're using in Basecamp:
```ruby
@@ -416,4 +437,4 @@ Action Cable is released under the MIT license:
Bug reports can be filed for the alpha development project here:
-* https://github.com/rails/actioncable/issues
+* https://github.com/rails/actioncable/issues \ No newline at end of file