How hotwired/turbo-rails works
Turbo Rails integrates browser-side Turbo navigation and stream subscriptions with Rails helpers, request handling, model broadcasts, and native-app navigation endpoints. The principal workflow is a browser interaction that Turbo sends to Rails, where Rails can render a full response, a frame response, or a stream update; broadcasts can also reach subscribed clients asynchronously. The README documents the broader product capabilities. Source evidence is sampled, so links without direct code evidence are grounded in that documentation rather than assumptions about unsampled implementation.
Main entry points: cable_stream_source_element.js Cable stream source · streams_channel.rb Streams channel · navigation_controller.rb Native navigation controller · broadcastable.rb Model broadcasts
Components 22
Browser interactions
- Turbo Drive
app/helpers/turbo/drive_helper.rb - Fetch requests
app/javascript/turbo/fetch_requests.js - Turbo entry
app/javascript/turbo/index.js - Attribute snakeizer
app/javascript/turbo/snakeize.js - Cable stream source
app/javascript/turbo/cable_stream_source_element.js - Cable client
app/javascript/turbo/cable.js
Rails integration
- Frame helpers
app/helpers/turbo/frames_helper.rb - Frame request handling
app/controllers/turbo/frames/frame_request.rb - Frame layout
app/views/layouts/turbo_rails/frame.html.erb
Live streams
- Stream helpers
app/helpers/turbo/streams_helper.rb - Stream action helpers
app/helpers/turbo/streams/action_helper.rb - Stream tag builder
app/models/turbo/streams/tag_builder.rb - Model broadcasts
app/models/concerns/turbo/broadcastable.rb - Broadcast jobs
app/jobs/turbo/streams - Streams channel
app/channels/turbo/streams_channel.rb - Channel broadcasts
app/channels/turbo/streams/broadcasts.rb
Native navigation
- Native navigation logic
app/controllers/turbo/native/navigation.rb - Native navigation controller
app/controllers/turbo/native/navigation_controller.rb - Navigation routes
config/routes.rb
Other components
- Browser user
- Rails application
- Action Cable
Connections 22
- Browser user → Turbo Drive: starts navigation
README.md - Turbo Drive → Fetch requests: submits forms
- Fetch requests → Rails application: sends requests
README.md - Rails application → Frame request handling: handles frame requests
README.md - Frame helpers → Frame layout: renders frames
README.md - Frame request handling → Frame layout: selects layout
README.md - Rails application → Stream helpers: renders stream tags
README.md - Stream helpers → Stream action helpers: builds actions
- Stream action helpers → Stream tag builder: builds tags
- Model broadcasts → Broadcast jobs: enqueues broadcasts
app/models/concerns/turbo/broadcastable.rb - Model broadcasts → Streams channel: calls broadcasts
app/models/concerns/turbo/broadcastable.rb - Streams channel → Channel broadcasts: broadcasts streams
- Broadcast jobs → Streams channel: delivers updates
- Streams channel → Action Cable: uses websocket
README.md - Cable stream source → Cable client: subscribes
app/javascript/turbo/cable_stream_source_element.js - Cable client → Action Cable: creates subscriptions
app/javascript/turbo/cable.js - Cable stream source → Attribute snakeizer: normalizes attributes
app/javascript/turbo/cable_stream_source_element.js - Turbo entry → Cable stream source: registers source
app/javascript/turbo/index.js - Browser user → Cable stream source: receives stream updates
README.md - Navigation routes → Native navigation controller: routes requests
config/routes.rb - Native navigation controller → Native navigation logic: handles navigation
- Rails application → Native navigation controller: responds to native navigation
README.md