routes.rbmaps request paths to Controllers. The way you structure these identifiers decides whether messages sent to the Channel are delivered to every subscriber, or just a subset that matches a given pattern.
consumerto subscribe to Channels. The subscription provides access to data that is
receivedfrom the server, as well as a mechanism for sending data to the sever.
params, similar to POSTing a form to a controller action. The Channel class can access these
paramsand use these values to compute and return a subscription identifier.
channelgenerator 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.
ExampleChannelwill receive any broadcasts sent to to the identifier
visitors. Operations broadcast there will be sent to everyone looking at your site. They will be automatically subscribed to your channel.
CableReadyand modify the
receivedmethod to check incoming data for CableReady broadcasts.
ExampleChannelthat you created will send any operations broadcast to
visitorsto all currently subscribed clients. In the code above, everyone on the site will see a Console Inspector message welcoming the latest member.
cable_readymultiple times to add more operations to these queues.
cable_readyis a singleton instance, which means that you can keep adding operations to a queue across multiple method calls.
selector, which is how you identify the target DOM element(s) for an operation. In fact, it's so common that you can just pass it as the first parameter, without a key.
cable_ready["visitors"], it returns a
CableReady::Channelsobject, which supports method chaining. That is, you can link up as many operations in sequence as you want, and they will be broadcast in the order that they were created.
broadcastmethod concludes the chain. After the operations have been dispatched, the queues are emptied.