rails-hotwire
Ruby on Rails Hotwire best practices for building interactive applications with Turbo Drive, Turbo Frames, Turbo Streams, Turbo 8 morphing, and Stimulus controllers. This skill should be used when writing, reviewing, or refactoring Hotwire-powered Rails code to ensure optimal patterns for navigation, partial page updates, real-time broadcasting, morphing, Stimulus controller design, error handling, and progressive enhancement. Triggers on tasks involving Turbo Frames, Turbo Streams, Turbo Drive, broadcasts, morphing, Stimulus controllers, ActionCable, turbo_stream_from, turbo_frame_tag, data-controller, data-action, or Hotwire performance. Complementary to rails-dev, rails-testing, rails-design-system, ruby-optimise, and ruby-refactor skills.
- License 许可
- MIT
- 所属仓库
- mikker/dotfiles
- 最近更新
- 2026-11-10
- Stars
- ★ 116
- Forks
- 4
01 前言 Front Matter
- name
- rails-hotwire
- description
- Ruby on Rails Hotwire best practices for building interactive applications with Turbo Drive, Turbo Frames, Turbo Streams, Turbo 8 morphing, and Stimulus controllers. This skill should be used when writing, reviewing, or refactoring Hotwire-powered Rails code to ensure optimal patterns for navigation, partial page updates, real-time broadcasting, morphing, Stimulus controller design, error handling, and progressive enhancement. Triggers on tasks involving Turbo Frames, Turbo Streams, Turbo Drive, broadcasts, morphing, Stimulus controllers, ActionCable, turbo_stream_from, turbo_frame_tag, data-controller, data-action, or Hotwire performance. Complementary to rails-dev, rails-testing, rails-design-system, ruby-optimise, and ruby-refactor skills.
02 资源文件 55
- 资产文件assets/templates/_template.md918 B
- 参考文档references/_sections.md2.6 KB
- 参考文档references/arch-avoid-client-state.md2.9 KB
- 参考文档references/arch-frame-vs-stream-decision.md2.4 KB
- 参考文档references/arch-importmap-management.md2.2 KB
- 参考文档references/arch-progressive-enhancement.md2.5 KB
- 参考文档references/arch-stimulus-boundaries.md3.1 KB
- 参考文档references/bcast-avoid-view-logic-in-models.md3.6 KB
- 参考文档references/bcast-debounce-n1.md2.6 KB
- 参考文档references/bcast-model-broadcasts.md2.7 KB
- 参考文档references/bcast-reconnect-handling.md2.7 KB
- 参考文档references/bcast-refresh-over-replace.md3.3 KB
- 参考文档references/bcast-scope-streams.md1.8 KB
- 参考文档references/bcast-signed-stream-names.md2.2 KB
- 参考文档references/drive-cache-control.md2.1 KB
- 参考文档references/drive-confirm-dialog.md3.1 KB
- 参考文档references/drive-error-recovery.md3.3 KB
- 参考文档references/drive-form-submissions.md2.1 KB
- 参考文档references/drive-prefetch-links.md2.3 KB
- 参考文档references/drive-progress-bar.md1.9 KB
- 参考文档references/drive-selective-disable.md1.9 KB
- 参考文档references/drive-visit-actions.md1.8 KB
- 参考文档references/frame-break-out.md3.6 KB
- 参考文档references/frame-dom-id.md2.8 KB
- 参考文档references/frame-empty-state.md2.8 KB
- 参考文档references/frame-lazy-loading.md2.9 KB
- 参考文档references/frame-promote-visits.md2.5 KB
- 参考文档references/frame-scope-navigation.md2.0 KB
- 参考文档references/frame-src-navigation.md2.0 KB
- 参考文档references/morph-enable-page-refresh.md1.9 KB
- 参考文档references/morph-frame-refresh.md2.3 KB
- 参考文档references/morph-permanent-elements.md2.3 KB
- 参考文档references/morph-scroll-preservation.md2.1 KB
- 参考文档references/morph-stimulus-reconnect.md3.8 KB
- 参考文档references/morph-vs-streams.md3.4 KB
- 参考文档references/perf-batch-streams.md2.0 KB
- 参考文档references/perf-frame-caching.md2.2 KB
- 参考文档references/perf-memory-leak-prevention.md2.9 KB
- 参考文档references/perf-optimistic-ui.md2.8 KB
- 参考文档references/perf-prefetch-strategic.md2.2 KB
- 参考文档references/stim-action-descriptors.md3.0 KB
- 参考文档references/stim-outlets-communication.md2.8 KB
- 参考文档references/stim-small-reusable-controllers.md3.3 KB
- 参考文档references/stim-values-reactive-state.md2.8 KB
- 参考文档references/stream-action-selection.md2.4 KB
- 参考文档references/stream-custom-actions.md2.4 KB
- 参考文档references/stream-http-delivery.md2.0 KB
- 参考文档references/stream-multi-target.md2.0 KB
- 参考文档references/stream-progressive-enhance.md1.7 KB
- 参考文档references/stream-websocket-source.md1.8 KB
- 参考文档references/test-broadcast-assertions.md2.2 KB
- 参考文档references/test-frame-navigation.md2.4 KB
- 参考文档references/test-stream-assertions.md2.5 KB
- 参考文档references/test-system-test-async.md2.4 KB
- 参考文档references/test-websocket-timing.md2.6 KB
03 SKILL.md 正文
Community Rails Hotwire Best Practices
Comprehensive guide for building interactive Rails applications with Hotwire (Turbo + Stimulus), maintained by Community. Contains 53 rules across 9 categories, prioritized by impact to guide automated refactoring and code generation. Follows the DHH "One Person Framework" philosophy: the server renders HTML, Turbo makes it feel like an SPA, Stimulus adds the sprinkle of JS where needed.
Default Policy: Adopt First, Opt Out Deliberately
Use Hotwire's conventions fully on the ordinary path: keep prefetch enabled, prefer refresh broadcasts with morphing for broad page updates, and use declarative model broadcasts for lifecycle-driven changes. Do not add architectural complexity for hypothetical scale or future requirements.
Opt out locally when correctness, the interaction, or measured cost warrants it—not only after a visible failure. Expensive hover requests, request fan-out from frames or refresh broadcasts, and operation-specific side effects are concrete reasons to depart from the default. Measure total work per user visit and across connected subscribers, not just the speed of individual endpoints.
The rules below express preferred defaults, not a prohibition on justified alternatives. Preserve the simple path and document exceptions where they are introduced.
When to Apply
Reference these guidelines when:
- Configuring Turbo Drive navigation, prefetching, and caching behavior
- Adding Turbo Frames for partial page updates and lazy loading
- Delivering Turbo Streams for surgical DOM mutations
- Broadcasting real-time updates over ActionCable
- Enabling Turbo 8 morphing for page refreshes
- Writing Stimulus controllers for client-side behavior
- Handling errors in Turbo navigation, frames, and WebSocket connections
- Choosing between Drive, Frames, Streams, Morphing, and Stimulus
- Testing Hotwire interactions in system and integration tests
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Navigation & Drive | CRITICAL | drive- |
| 2 | Turbo Frames | CRITICAL | frame- |
| 3 | Turbo Streams | HIGH | stream- |
| 4 | Broadcasting & Real-Time | HIGH | bcast- |
| 5 | Morphing & Page Refresh | HIGH | morph- |
| 6 | Performance Optimization | MEDIUM-HIGH | perf- |
| 7 | Stimulus Patterns | MEDIUM-HIGH | stim- |
| 8 | Architecture Decisions | MEDIUM | arch- |
| 9 | Testing Hotwire | MEDIUM | test- |
Quick Reference
1. Navigation & Drive (CRITICAL)
drive-prefetch-links- Enable link prefetching for instant navigationdrive-form-submissions- Use Turbo Drive for form submissionsdrive-visit-actions- Control history with visit actionsdrive-cache-control- Configure Turbo cache for preview pagesdrive-selective-disable- Disable Turbo Drive on incompatible pagesdrive-progress-bar- Customize the Turbo progress bardrive-confirm-dialog- Use data-turbo-confirm for destructive actionsdrive-error-recovery- Handle Turbo navigation and fetch errors gracefully
2. Turbo Frames (CRITICAL)
frame-lazy-loading- Defer frame loading until viewport entryframe-scope-navigation- Scope navigation within framesframe-src-navigation- Use src for dynamic frame contentframe-break-out- Handle frame breakout for redirectsframe-promote-visits- Promote frame navigation to page visitsframe-dom-id- Use dom_id for frame identificationframe-empty-state- Provide meaningful frame loading states
3. Turbo Streams (HIGH)
stream-progressive-enhance- Always provide HTML fallback for streamsstream-action-selection- Choose the right stream action for DOM mutationsstream-multi-target- Use targets for multi-element updatesstream-http-delivery- Deliver streams via HTTP for form responsesstream-websocket-source- Connect WebSocket sources in the bodystream-custom-actions- Register custom stream actions for complex DOM updates
4. Broadcasting & Real-Time (HIGH)
bcast-model-broadcasts- Use broadcasts_refreshes for simple model updatesbcast-debounce-n1- Debounce broadcasts to prevent N+1 broadcast stormsbcast-scope-streams- Scope broadcast streams to accounts or usersbcast-refresh-over-replace- Prefer broadcast refresh over granular stream updatesbcast-avoid-view-logic-in-models- Keep broadcasting logic out of modelsbcast-signed-stream-names- Use signed stream names for securitybcast-reconnect-handling- Handle WebSocket disconnection and reconnection
5. Morphing & Page Refresh (HIGH)
morph-enable-page-refresh- Enable morphing for page refreshesmorph-permanent-elements- Mark stateful elements as permanentmorph-scroll-preservation- Preserve scroll position during morphingmorph-stimulus-reconnect- Handle Stimulus controller reconnection after morphmorph-frame-refresh- Use refresh='morph' on frames for additive contentmorph-vs-streams- Choose morphing over complex stream orchestration
6. Performance Optimization (MEDIUM-HIGH)
perf-optimistic-ui- Implement optimistic UI updates before server confirmationperf-batch-streams- Batch multiple stream updates into single responsesperf-frame-caching- Cache Turbo Frame responses with fragment cachingperf-prefetch-strategic- Disable prefetch on expensive endpointsperf-memory-leak-prevention- Clean up subscriptions and event listeners
7. Stimulus Patterns (MEDIUM-HIGH)
stim-outlets-communication- Use outlets for cross-controller communicationstim-values-reactive-state- Use Values API for reactive controller statestim-action-descriptors- Use declarative action descriptors over addEventListenerstim-small-reusable-controllers- Keep Stimulus controllers small and reusable
8. Architecture Decisions (MEDIUM)
arch-progressive-enhancement- Follow the progressive enhancement hierarchyarch-frame-vs-stream-decision- Use frames for scoped navigation, streams for multi-target updatesarch-importmap-management- Pin JavaScript dependencies with import mapsarch-avoid-client-state- Keep state on the server, not the clientarch-stimulus-boundaries- Use Stimulus only for client-side behavior
9. Testing Hotwire (MEDIUM)
test-system-test-async- Wait for Turbo updates in system teststest-stream-assertions- Use Turbo Stream test helpers in integration teststest-broadcast-assertions- Assert broadcasts with Turbo test helperstest-frame-navigation- Test frame navigation with scoped assertionstest-websocket-timing- Handle WebSocket connection timing in system tests
How to Use
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
Reference Files
| File | Description |
|---|---|
| references/_sections.md | Category definitions and ordering |
| assets/templates/_template.md | Template for new rules |
| metadata.json | Version and reference information |
04 同仓库更多 Skills
unslop
Cut AI tells from any writing.
stageshow
Build faux product UI that looks like a real product, as a still illustration or an animated demo with a cursor. Browser and app windows, dashboards, phones, notifications, terminals, bento grids and cursor walkthroughs, framed, masked and cropped the way a marketing page, feature card or docs hero needs them. Use whenever someone wants a fake or mocked UI, a product demo or walkthrough animation, a hero or feature-card illustration of an app, a product shot in the style of a polished marketing site, or an animated cursor doing things in an interface, even if they never say "faux UI". React and plain CSS.
clean-copy
Cut interface copy that shouldn't exist — captions that restate a label, hints that pre-empt a worry the user never had, warnings that are scar tissue from a fixed bug. Use when writing or reviewing any user-facing string (labels, hints, empty states, toasts, confirmations, button text), or when asked to clean up / tighten copy.
elyx
Elyx is a design tool with local, AI-friendly `.elyx` files for screens, components, layouts, flows, and design systems. This skill is only available to agents running in external harnesses while using the Elyx CLI. It is unavailable and must not be used when running in the ACP harness inside the Elyx app. In external harnesses, use this skill before reading, reasoning about, or answering any question that touches Elyx or `.elyx` files — authoring, editing, validating, inspecting, reviewing, refactoring, comparing, or recommending changes, including read-only analysis where you produce no edit. Do not reason about `.elyx` from source text alone; imports, instances, overrides, and layout only resolve through the tools.
uikit-app-modernization
Modernizes UIKit apps for multi-window environments by replacing legacy shared-state APIs with context-appropriate modern alternatives. This includes references to mainScreen, interfaceOrientation, application and scene lifecycle, as well as safe area inset updates.
swiftui-whats-new-27
New SwiftUI APIs, behaviors, and deprecations in the 2027 OS releases (iOS 27 and aligned macOS/watchOS/tvOS/visionOS). Consult when asked what's new in SwiftUI 27, or when working with: - @State compile errors after an SDK update ("used before being initialized", "invalid redeclaration of synthesized property") or @State becaming a macro - @ViewBuilder/@ContentBuilder ambiguous overloads or type-check regressions; drag-to-reorder in any container (List, stacks, grids, custom layouts) via reorderable()/reorderContainer and its drag-and-drop - AsyncImage caching, reloading on scroll, or a custom URLSession - Swipe actions outside List (ScrollView, LazyVStack, LazyVGrid) via swipeActions()/swipeActionsContainer() - Toolbar overflow, visibility (visibilityPriority, ToolbarOverflowMenu, toolbarMinimizeBehavior), and pinning - Presenting a confirmationDialog or alert from an optional item binding