用途:该代理专注 Hotwire Turbo(Turbo Drive、Turbo Frames、Turbo Streams)在 Ruby on Rails 应用中的落地,目标是以最少 JavaScript 构建快速响应的页面,并按渐进增强与优雅降级原则工作。技术栈涉及 Ruby 3.3、Rails 8.1、Hotwire(Turbo + Stimulus)、ViewComponent、Tailwind CSS、RSpec。
主要能力:配置 Turbo Drive,包括 Turbo 8 的 morphing 页面刷新(turbo_refreshes_with method: :morph, scroll: :preserve)、CSS 视图过渡、悬停预取与永久元素;使用带稳定 ID 的 Turbo Frames 做局部更新,支持 turbo_frame_tag dom_id(@resource)、data: { turbo_frame: "_top" } 跳出框架、loading: :lazy 延迟加载与内联编辑;使用 Turbo Streams 执行 append、prepend、replace、update、remove、before、after、morph、refresh 等 DOM 更新,并通过 ActionCable 做模型广播(turbo_stream_from)。
使用方式:开发用 bin/dev 启动,bin/rails console 与 bin/rails routes 辅助;测试用 bundle exec rspec spec/requests/ 等命令,提交前用 bundle exec rubocop -a 检查视图与控制器。流式响应需提供 format.html 回退,复杂多段更新使用 create.turbo_stream.erb 模板,简单更新可内联 render turbo_stream:,并附带 flash 消息;请求规格通过 Accept: text/vnd.turbo-stream.html 触发流式响应。
限制与边界:始终为 streams 编写请求规格、用 frames 做局部更新并保证降级;全局禁用 Turbo Drive 或新增自定义 Turbo 事件前需先确认。避免不带 frame ID 的 turbo_frame_tag、缺失 HTML 回退、错误混用流式与整页渲染、破坏浏览器历史。参考资料包括 turbo-drive.md、turbo-frames.md、turbo-streams.md、broadcasts.md、testing.md。其他如具体收费与平台支持等事实暂未提供。