CableReady
Search…
Installation
If you're running StimulusReflex or other CableReady-powered libraries (such as Optimism or Futurism), CableReady is already installed as a dependency and you can move on to Setup. πŸŽ‰
CableReady has both client (npm package) and server (Ruby gem) components which need to be installed. It is vitally important that you make sure that your server and client versions match exactly.
There can be issues with conflicting versions introduced when we're testing a pre-release build, since yarn will typically install the most recent package available, while Rubygems will install the last official release. 🀯
1
bundle add cable_ready
2
yarn add cable_ready
Copied!
You can manually tweak and/or lock the versions you want to install by modifying Gemfile and package.json respectively, then re-running bundle install && yarn install.

ActionCable

CableReady depends on the ActionCable framework (installed by default as part of Ruby on Rails) to handle sending data to the client over websockets. You must have ActionCable installed on both the client and server... and it will be unless you've disabled it.
You can check your package.json to verify that @rails/actioncable is installed. If you have trouble with ActionCable, consider verifying that it's installed correctly.

Redis

​Redis for everything: caching, sessions, jobs and yes, ActionCable. Redis is a dependency for StimulusReflex; the installation task sets up Redis for ActionCable's subscription adapter in the development environment.
While Redis in development is not mandatory for standalone CableReady use, we do recommend it:
Gemfile
1
gem "redis", ">= 4.0", :require => ["redis", "redis/connection/hiredis"]
2
gem "hiredis"
Copied!
config/cable.yml
1
development:
2
adapter: redis
3
url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
4
channel_prefix: your_application_development
Copied!

Rails 5.2

The CableReady documentation assumes that you are running Rails 6.x. It is possible to use CableReady with Rails 5.2, but you must make some adjustments to your configuration.
  1. 1.
    Replace actioncable with @rails/actioncable in package.json
    • yarn remove actioncable
    • yarn add @rails/actioncable
  2. 2.
    Replace any instance of import Actioncable from "actioncable" with import { createConsumer } from "@rails/actioncable"
    • This imports the createConsumer function directly
    • Previously, you might call createConsumer() on the Actioncable import: Actioncable.createConsumer()
    • Now, you can reference createConsumer() directly

Polyfills for IE11

If you need to provide support for older browsers, you can yarn add @cable_ready/polyfills and include them before your Stimulus controllers (if any) and CableReady channels:
app/javascript/packs/application.js
1
// other stuff
2
import '@cable_ready/polyfills'
3
import 'channels'
4
import 'controllers'
Copied!
Last modified 11mo ago
Export as PDF
Copy link