Live Streaming
To see how streaming works, letâs create a controller called LiveAssetsController at app/controllers/live_assets_controller.rb that includes the ActionController::Live functionality and streams âhello worldâ continuously:
live_assets/1_live/app/controllers/live_assets_controller.rb | |
â | âclassâ LiveAssetsController < ActionController::Base |
â | include ActionController::Live |
â | |
â | âdefâ hello |
â | âwhileâ true |
â | response.stream.write â"Hello World\n"â |
â | sleep 1 |
â | âendâ |
â | ârescueâ IOError |
â | response.stream.close |
â | âendâ |
â | âendâ |
Our controller provides an action named hello that streams Hello World every second. If, for any reason, the connection between the server and ...
Get Crafting Rails 4 Applications, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.