Broadcasting Updates with Action Cable
Get an overview of how to broadcast the new updates using action cable.
We'll cover the following
Updates using web sockets
Up until now, our users’ web browsers have requested information from our Rails app either by going directly to a URL or by clicking a link or button. It’s also possible to send information from our Rails app to our users’ browsers without a direct request. The technology that enables this is called Web Sockets. Prior to Rails 5, setting this up was fairly involved, but Rails 5 introduced Action Cable, which simplifies pushing data to all connected browsers.
We can use Action Cable and Web Sockets to broadcast price updates to the users browsing the catalog. To see why we’d want to do this, bring up the Depot application in two browser windows or tabs. In the first window, display the catalog. In the second window, update the price of an item. Return to the first window and add that item to the cart. At this point, the cart shows the updated price, but the catalog shows the original price. Let’s see this in action.
A running application
We have already performed all required steps for you. Just run the following application to see things in action.
Get hands-on with 1200+ tech skills courses.