hotwire
This skill should be used when the user asks about "Hotwire", "Turbo", "Turbo Drive", "Turbo Frames", "Turbo Streams", "Stimulus", "Stimulus controllers", "Stimulus values", "Stimulus targets", "Stimulus actions", "import maps", "live updates", "partial page updates", "SPA-like behavior", "real-time updates", "turbo_frame_tag", "turbo_stream", "broadcast", or needs guidance on building modern Rails 7+ frontends without heavy JavaScript frameworks.
What this skill does
# Hotwire for Rails 7+
Comprehensive guide to building modern, reactive web applications with Hotwire (Turbo + Stimulus) in Rails 7+.
## What is Hotwire?
Hotwire enables "fast, modern, progressively enhanced web applications without using much JavaScript." It sends HTML over the wire instead of JSON, keeping business logic on the server.
**Three components:**
1. **Turbo Drive** - Accelerates navigation by intercepting clicks and replacing `<body>`
2. **Turbo Frames** - Decompose pages into independently-updatable sections
3. **Turbo Streams** - Deliver live partial page updates via WebSocket, SSE, or HTTP
4. **Stimulus** - Modest JavaScript framework for behavior
## Turbo Drive
Turbo Drive intercepts link clicks and form submissions, fetching via `fetch` and replacing `<body>` while merging `<head>`. The window, document, and `<html>` persist across navigations.
### Disabling for Specific Elements
```erb
<%# Disable Turbo for external links or file downloads %>
<%= link_to "Download PDF", pdf_path, data: { turbo: false } %>
<%# Disable for forms that need full page reload %>
<%= form_with model: @export, data: { turbo: false } do |f| %>
```
### Progress Bar
```css
.turbo-progress-bar {
background-color: #3b82f6;
height: 3px;
}
```
## Turbo Frames
Frames wrap page segments in `<turbo-frame>` elements for scoped navigation. Only matching frames extract from server responses.
### Frame Attributes
| Attribute | Purpose |
|-----------|---------|
| `id` | Required. Unique identifier to match frames between requests |
| `src` | URL for eager-loading frame content on page load |
| `loading="lazy"` | Delay loading until frame becomes visible |
| `target` | Navigation scope: `_top` (full page), `_self`, or frame ID |
| `data-turbo-action` | Promote to browser history (`advance` or `replace`) |
### Basic Frame
```erb
<%# app/views/articles/show.html.erb %>
<h1><%= @article.title %></h1>
<%= turbo_frame_tag @article do %>
<p><%= @article.body %></p>
<%= link_to "Edit", edit_article_path(@article) %>
<% end %>
<%# app/views/articles/edit.html.erb %>
<%= turbo_frame_tag @article do %>
<%= render "form", article: @article %>
<% end %>
```
### Lazy Loading
```erb
<%# Load content when frame becomes visible %>
<%= turbo_frame_tag "comments",
src: article_comments_path(@article),
loading: :lazy do %>
<p>Loading comments...</p>
<% end %>
```
### Breaking Out of Frames
```erb
<%# Navigate entire page %>
<%= link_to "View Full", article_path(@article), data: { turbo_frame: "_top" } %>
<%# Target different frame %>
<%= link_to "Preview", preview_path(@article), data: { turbo_frame: "preview_panel" } %>
```
### Frame State Attributes
During navigation, frames receive `[aria-busy="true"]`. After completion, `[complete]` is set on the frame.
## Turbo Streams
Streams deliver DOM changes as `<turbo-stream>` elements specifying action and target.
### Stream Actions (9 total)
| Action | Description |
|--------|-------------|
| `append` | Add content to end of target |
| `prepend` | Add content to start of target |
| `replace` | Replace entire target element |
| `update` | Replace target's inner content only |
| `remove` | Delete target element |
| `before` | Insert before target element |
| `after` | Insert after target element |
| `morph` | Intelligently morph changes (variant of replace/update) |
| `refresh` | Refresh page or frame |
### HTTP Stream Response
```ruby
# app/controllers/comments_controller.rb
def create
@comment = @article.comments.build(comment_params)
if @comment.save
respond_to do |format|
format.turbo_stream # Renders create.turbo_stream.erb
format.html { redirect_to @article }
end
else
render :new, status: :unprocessable_entity
end
end
```
```erb
<%# app/views/comments/create.turbo_stream.erb %>
<%= turbo_stream.append "comments", @comment %>
<%= turbo_stream.update "comment_count", @article.comments.count %>
<%= turbo_stream.replace "new_comment", partial: "form", locals: { comment: Comment.new } %>
```
### Inline Stream Response
```ruby
def destroy
@comment.destroy
respond_to do |format|
format.turbo_stream do
render turbo_stream: [
turbo_stream.remove(@comment),
turbo_stream.update("comment_count", @article.comments.count)
]
end
format.html { redirect_to @article }
end
end
```
### Broadcasting via WebSocket
```ruby
# app/models/comment.rb
class Comment < ApplicationRecord
belongs_to :article
after_create_commit -> {
broadcast_append_to article, target: "comments"
}
after_destroy_commit -> {
broadcast_remove_to article
}
end
```
```erb
<%# Subscribe to broadcasts %>
<%= turbo_stream_from @article %>
<div id="comments">
<%= render @article.comments %>
</div>
```
### WebSocket/SSE Source
```erb
<%# Persistent connection for real-time updates %>
<turbo-stream-source src="ws://example.com/updates"></turbo-stream-source>
```
## Stimulus
Stimulus is "a JavaScript framework with modest ambitions." It enhances server-rendered HTML using data attributes.
### Controller Structure
```javascript
// app/javascript/controllers/hello_controller.js
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = ["name", "output"]
static values = { greeting: { type: String, default: "Hello" } }
static classes = ["active"]
connect() {
// Called when controller connects to DOM
}
disconnect() {
// Called when controller disconnects - clean up here
}
greet() {
this.outputTarget.textContent = `${this.greetingValue}, ${this.nameTarget.value}!`
}
}
```
### Naming Conventions
| Context | Convention | Example |
|---------|------------|---------|
| Controller file | snake_case or kebab-case | `hello_controller.js`, `date-picker_controller.js` |
| Controller identifier | kebab-case in HTML | `data-controller="date-picker"` |
| Targets | camelCase | `static targets = ["firstName"]` |
| Values | camelCase | `static values = { itemCount: Number }` |
| Methods | camelCase | `submitForm()` |
### Targets
Define elements to reference within controller:
```javascript
static targets = ["query", "results", "errorMessage"]
```
**Generated properties:**
| Property | Purpose |
|----------|---------|
| `this.queryTarget` | First matching element (throws if missing) |
| `this.queryTargets` | Array of all matching elements |
| `this.hasQueryTarget` | Boolean existence check |
**Target callbacks:**
```javascript
queryTargetConnected(element) {
// Called when target is added to DOM
}
queryTargetDisconnected(element) {
// Called when target is removed from DOM
}
```
```erb
<div data-controller="search">
<input data-search-target="query">
<div data-search-target="results"></div>
</div>
```
### Values
Read/write typed data attributes:
```javascript
static values = {
index: Number, // data-controller-index-value
url: String, // data-controller-url-value
active: Boolean, // data-controller-active-value
items: Array, // data-controller-items-value (JSON)
config: Object // data-controller-config-value (JSON)
}
```
**Five supported types:** Array, Boolean, Number, Object, String
**Default values:**
```javascript
static values = {
count: { type: Number, default: 0 },
url: { type: String, default: "/api" }
}
```
**Change callbacks:**
```javascript
countValueChanged(value, previousValue) {
// Called on initialize and when value changes
this.element.textContent = value
}
```
### Actions
Connect DOM events to controller methods:
**Format:** `event->controller#method`
```erb
<button data-action="click->gallery#next">Next</button>
```
**Event shorthand** (common defaults):
- `<button>`, `<a>` → `click`
- `<form>` → `submit`
- `<input>`, `<textarea>` → `input`
- `<select>` → `change`
- `<details>` → `toggle`
```erb
<%# Equivalent to click->gallery#next %>
<button data-Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.