Skip to content

Commit 76ca38e

Browse files
authored
Merge pull request rails#46679 from ghiculescu/action-cable-guide [ci-skip]
Clarify how to use a standalone Action Cable server
2 parents 7ebbe32 + cd04f3b commit 76ca38e

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

guides/source/action_cable_overview.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,10 @@ For a full list of all configuration options, see the
876876
877877
## Running Standalone Cable Servers
878878
879+
Action Cable can either run as part of your Rails application, or as
880+
a standalone server. In development, running as part of your Rails app
881+
is generally fine, but in production you should run it as a standalone.
882+
879883
### In App
880884
881885
Action Cable can run alongside your Rails application. For example, to
@@ -890,14 +894,15 @@ end
890894
```
891895
892896
You can use `ActionCable.createConsumer()` to connect to the cable
893-
server if `action_cable_meta_tag` is invoked in the layout. Otherwise, A path is
897+
server if [`action_cable_meta_tag`][] is invoked in the layout. Otherwise, a path is
894898
specified as first argument to `createConsumer` (e.g. `ActionCable.createConsumer("/websocket")`).
895899
896900
For every instance of your server you create, and for every worker your server
897901
spawns, you will also have a new instance of Action Cable, but the Redis or
898902
PostgreSQL adapter keeps messages synced across connections.
899903
900904
[`config.action_cable.mount_path`]: configuring.html#config-action-cable-mount-path
905+
[`action_cable_meta_tag`]: https://api.rubyonrails.org/classes/ActionCable/Helpers/ActionCableHelper.html#method-i-action_cable_meta_tag
901906
902907
### Standalone
903908
@@ -913,14 +918,24 @@ Rails.application.eager_load!
913918
run ActionCable.server
914919
```
915920
916-
Then you start the server using a binstub in `bin/cable` ala:
921+
Then to start the server:
917922
918923
```
919-
#!/bin/bash
920924
bundle exec puma -p 28080 cable/config.ru
921925
```
922926
923-
The above will start a cable server on port 28080.
927+
This starts a cable server on port 28080. To tell Rails to use this
928+
server, update your config:
929+
930+
```ruby
931+
# config/environments/development.rb
932+
Rails.application.configure do
933+
config.action_cable.mount_path = nil
934+
config.action_cable.url = "ws://localhost:28080" # use wss:// in production
935+
end
936+
```
937+
938+
Finally, ensure you have [configured the consumer correctly](#consumer-configuration).
924939
925940
### Notes
926941

0 commit comments

Comments
 (0)