From the course: Hotwire: Reactive Ruby on Rails Applications
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Broadcasting messages: Part 1 - Ruby on Rails Tutorial
From the course: Hotwire: Reactive Ruby on Rails Applications
Broadcasting messages: Part 1
- [Instructor] You can have several browsers subscribed to a stream and broadcast messages to all of them from anywhere in the application. For this to work, you need to install Redis and have it active. Open the terminal and I'm going to use Home Brew to install it on mac os. Then use the command suggested by the package manager to start it. Now you can start the rail server. Open the listing template and under each one add the Turbo stream from Helper and give it an identifier. This will be the subscription. If it already exists, the server will add a new session. If it doesn't, it'll create a new one. Below, create a Diff with an id, for example, message. To do a first test, we'll use this element to receive a value. Reload the page in the browser and let's see the elements from Dev tools. Just below the h1, the Helper has generated the tag turbo cable stream source with a turbo streams channel name…