Skip to main content
Deploying Turbo Streams or Action Cable with a Rails app involves provisioning a redis cluster and a few updates to your application.

Provisioning Redis

Before proceeding, verify that your application is already set up to use Redis. Examine your Gemfile and look for the following lines:
If the second line is commented out, uncomment it and then run bundle install. Rails will automatically have done this for you if it detected the redis-server executable on your machine at that time the application was created. Now that Rails is ready to make use of Redis, lets deploy a redis cluster:
Once again, you can set a name for the database, chose a primary region as well as a number of replica regions, enable eviction, and select a plan. The most important line in this output is the second to the last one which will contain a URL starting with redis:. The URL you see will be considerably longer than the one you see above. You will need to provide this URL to Rails, and with Fly.io this is done via secrets. Run the following command replacing the url with the one from the output above:
Now you are ready. Rails is set up to use redis, knows where to find the redis instance, and the instance is deployed. Now onto the implementation:

Adding Turbo Streams to your Application

There are very few steps to make this work, writing very few lines of code Let’s start with the turbo_stream_for helper, which under the hood uses Turbo::StreamsChannel. Modify app/views/names/index.html.erb to stream from “names”:
And we complete the client changes by modifying app/views/names/_name.html.erb to identify the turbo frame:
There is only one step left, and that is to modify app/controllers/names_controller.rb to broadcast changes as updates are made:

Deployment and testing

By now it should be no surprise that deployment is as easy as fly deploy and fly apps open. Once that is done, copy the browser URL, open a second browser window (it can even be a different browser or even on a different machine), and paste the URL into the new window. With one browser window open to the index page, use the other browser to change one of the names. Once you click “Update name” the index list in the original window will instantly update. Of course, if this were a real application, inserting and removing names would cause those changes to be broadcast. As they say, this is left as an exercise for the student.

Arrived at Destination

You have successfully built, deployed, and connected to your first Rails application on Fly.io. We’ve accomplished a lot with only just over a handful of lines of code and just over a dozen commands. When you are ready, proceed to a recap.