How does Turbo work with Action Cable?

18-Oct-2025 543
Modern Rails makes it easy to build real-time features into your app. With the turbo-rails library, you can add a call to turbo_stream_from in a view file, and that will set up a WebSocket connection between your app server and all browsers that render that view. Your application can then use the broadcast_* family of methods to send elements to all those browsers. Turbo, on receiving the elements, will add them to the DOM, which will trigger DOM updates. Users thus see updates from the server in real-time, without having had to make separate requests. The amazing thing is that the broadcast_* methods can be called from any process (e.g. asynchronous jobs, the Rails console etc), and not just the Rails server process. How does this magic work? What is a WebSocket connection and how is it different from HTTP? How do Turbo and ActionCable create a WebSocket connection? How do the broadcast_* methods work across processes? Are these connections secure?.
Use coupon code:

RUBYONRAILS

to get 30% discount on our bundle!
Prepare for your next tech interview with our comprehensive collection of programming interview guides. Covering JavaScript, Ruby on Rails, React, and Python, these highly-rated books offer thousands of essential questions and answers to boost your interview success. Buy our 'Ultimate Job Interview Preparation eBook Bundle' featuring 2200+ questions across multiple languages. Ultimate Job Interview Preparation eBook Bundle