To demonstrate a basic setup, we're going to use the built-in Rails
channel generator to create an ActionCable Channel class called
ExampleChannel. If this is the first time you've generated a Channel, a number of important files and folders will be created.
bundle exec rails generate channel example
In this configuration, every client that subscribes to
ExampleChannel will receive any broadcasts sent to to a stream called
visitors. We'll talk more about streams soon. For now,
visitors is for operations that will be sent to everyone currently looking at your site.
app/channels/example_channel.rbclass ExampleChannel < ApplicationCable::Channeldef subscribedstream_from "visitors"endend
CableReady and modify the
received method to check incoming data for CableReady broadcasts.
That's it! Let's get this party started and learn how to broadcast operations.