aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/README.md
diff options
context:
space:
mode:
authorVipul A M <vipulnsward@gmail.com>2016-06-29 15:29:59 -0700
committerGitHub <noreply@github.com>2016-06-29 15:29:59 -0700
commite5c5b6f2ee81aa64bc3d87ec15d8cc9983dfdaaf (patch)
tree45d364071b8580e96b88f0644909727562598031 /actioncable/README.md
parent98131f751946d2d0a4868fd04ab058459fc28ed1 (diff)
parent1713075a80ecaaf18b1d8927aaa3b9836cc68214 (diff)
downloadrails-e5c5b6f2ee81aa64bc3d87ec15d8cc9983dfdaaf.tar.gz
rails-e5c5b6f2ee81aa64bc3d87ec15d8cc9983dfdaaf.tar.bz2
rails-e5c5b6f2ee81aa64bc3d87ec15d8cc9983dfdaaf.zip
Merge pull request #24991 from maclover7/actioncable-npm-docs
Add documentation about Action Cable npm package
Diffstat (limited to 'actioncable/README.md')
-rw-r--r--actioncable/README.md68
1 files changed, 68 insertions, 0 deletions
diff --git a/actioncable/README.md b/actioncable/README.md
index 50523d4b0f..28e2602cbf 100644
--- a/actioncable/README.md
+++ b/actioncable/README.md
@@ -458,6 +458,74 @@ with all the popular application servers -- Unicorn, Puma and Passenger.
Action Cable does not work with WEBrick, because WEBrick does not support the
Rack socket hijacking API.
+## Frontend assets
+
+Action Cable's frontend assets are distributed through two channels: the
+official gem and npm package, both titled `actioncable`.
+
+### Gem usage
+
+Through the `actioncable` gem, Action Cable's frontend assets are
+available through the Rails Asset Pipeline. Create a `cable.js` or
+`cable.coffee` file (this is automatically done for you with Rails
+generators), and then simply require the assets:
+
+In JavaScript...
+
+```javascript
+//= require action_cable
+```
+
+... and in CoffeeScript:
+
+```coffeescript
+#= require action_cable
+```
+
+### npm usage
+
+In addition to being available through the `actioncable` gem, Action Cable's
+frontend JS assets are also bundled in an officially supported npm module,
+intended for usage in standalone frontend applications that communicate with a
+Rails application. A common use case for this could be if you have a decoupled
+frontend application written in React, Ember.js, etc. and want to add real-time
+WebSocket functionality.
+
+### Installation
+
+```
+npm install actioncable --save
+```
+
+### Usage
+
+The `ActionCable` constant is available as a `require`-able module, so
+you only have to require the package to gain access to the API that is
+provided.
+
+In JavaScript...
+
+```javascript
+ActionCable = require('actioncable')
+
+var cable = ActionCable.createConsumer('wss://RAILS-API-PATH.com/cable')
+
+cable.subscriptions.create('AppearanceChannel', {
+ // normal channel code goes here...
+});
+```
+
+and in CoffeeScript...
+
+```coffeescript
+ActionCable = require('actioncable')
+
+cable = ActionCable.createConsumer('wss://RAILS-API-PATH.com/cable')
+
+cable.subscriptions.create 'AppearanceChannel',
+ # normal channel code goes here...
+```
+
## License
Action Cable is released under the MIT license: