jpskill.com
🛠️ 開発・MCP コミュニティ

hotwire-patterns

Railsのフロントエンド開発で、Hotwire、Stimulus、Turboといった技術を使う際に、関連するコードパターンを自動で認識し、開発を効率化するための支援をするSkill。

📜 元の英語説明(参考)

Stimulus and Turbo patterns for Rails frontend development. Automatically invoked when working with Hotwire, Stimulus controllers, Turbo frames/streams, progressive enhancement, or modern Rails JavaScript. Triggers on "Stimulus", "Turbo", "Hotwire", "turbo_frame", "turbo_stream", "Stimulus controller", "data-controller", "data-action", "progressive enhancement", "SPA-like".

🇯🇵 日本人クリエイター向け解説

一言でいうと

Railsのフロントエンド開発で、Hotwire、Stimulus、Turboといった技術を使う際に、関連するコードパターンを自動で認識し、開発を効率化するための支援をするSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o hotwire-patterns.zip https://jpskill.com/download/10044.zip && unzip -o hotwire-patterns.zip && rm hotwire-patterns.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/10044.zip -OutFile "$d\hotwire-patterns.zip"; Expand-Archive "$d\hotwire-patterns.zip" -DestinationPath $d -Force; ri "$d\hotwire-patterns.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して hotwire-patterns.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → hotwire-patterns フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

Rails向けHotwireパターン

StimulusとTurboを用いて、現代的でインタラクティブなRailsアプリケーションを構築するためのパターン集です。

このSkillが適用できる場面

  • インタラクティブな挙動のためのStimulusコントローラの作成
  • 部分的なページ更新のためのTurboフレームの実装
  • リアルタイム更新のためのTurboストリームの使用
  • プログレッシブエンハンスメントのパターン
  • フォームの拡張とバリデーション
  • ActionCableによるリアルタイム機能

中核となる理念

HTML over the wire: HotwireはJSONではなくHTMLをサーバーから送信します。JavaScriptは、サーバーでレンダリングされたHTMLを置き換えるのではなく、拡張します。

  • プログレッシブエンハンスメント: JavaScriptなしでも動作し、JavaScriptで拡張されます
  • Server-first: ビジネスロジックはサーバー上に保持されます
  • Minimal JavaScript: HTMLをインタラクティブにするのに十分なJSのみ

クイックリファレンス

コンポーネント 目的 使用場面
Stimulus JavaScriptの挙動 HTMLにインタラクティビティを追加する場合
Turbo Drive SPAナビゲーション すべてのリンク/フォームのデフォルト
Turbo Frames 部分的な更新 ページの一部を更新する場合
Turbo Streams 複数ターゲットの更新 複数の要素を更新する場合

詳細なドキュメント

  • stimulus.md - Stimulusコントローラのパターン
  • turbo.md - Turboフレームとストリームのパターン

一般的なパターン

Stimulusコントローラの基本

// app/javascript/controllers/toggle_controller.js
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
  static targets = ["content"]
  static classes = ["hidden"]
  static values = { open: { type: Boolean, default: false } }

  toggle() {
    this.openValue = !this.openValue
  }

  openValueChanged() {
    this.contentTarget.classList.toggle(this.hiddenClass, !this.openValue)
  }
}
<div data-controller="toggle" data-toggle-hidden-class="hidden">
  <button data-action="toggle#toggle">Toggle</button>
  <div data-toggle-target="content">Content here</div>
</div>

Turboフレームの基本

<turbo-frame id="messages">
  <%= render @messages %>
</turbo-frame>

<%= link_to "Load more", messages_path(page: 2), data: { turbo_frame: "messages" } %>

Turboストリームの基本

<%# app/views/messages/create.turbo_stream.erb %>
<%= turbo_stream.prepend "messages", @message %>
<%= turbo_stream.update "message_count", Message.count %>

統合のヒント

Railsビューヘルパー

<%# Stimulus data attributes %>
<%= tag.div data: { controller: "dropdown", dropdown_open_value: false } do %>
  ...
<% end %>

<%# Turbo frame %>
<%= turbo_frame_tag "user_#{user.id}" do %>
  <%= render user %>
<% end %>

特定のリンクでTurboを無効にする

<%= link_to "Download", file_path, data: { turbo: false } %>
<%= link_to "External", "https://example.com", data: { turbo_frame: "_top" } %>
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Hotwire Patterns for Rails

Patterns for building modern, interactive Rails applications with Stimulus and Turbo.

When This Skill Applies

  • Creating Stimulus controllers for interactive behaviors
  • Implementing Turbo frames for partial page updates
  • Using Turbo streams for real-time updates
  • Progressive enhancement patterns
  • Form enhancements and validations
  • Real-time features with ActionCable

Core Philosophy

HTML over the wire: Hotwire sends HTML from the server, not JSON. JavaScript enhances server-rendered HTML rather than replacing it.

  • Progressive enhancement: Works without JavaScript, enhanced with it
  • Server-first: Business logic stays on the server
  • Minimal JavaScript: Just enough JS to make HTML interactive

Quick Reference

Component Purpose Use When
Stimulus JavaScript behaviors Adding interactivity to HTML
Turbo Drive SPA navigation Default for all links/forms
Turbo Frames Partial updates Update part of page
Turbo Streams Multi-target updates Update multiple elements

Detailed Documentation

Common Patterns

Stimulus Controller Basics

// app/javascript/controllers/toggle_controller.js
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
  static targets = ["content"]
  static classes = ["hidden"]
  static values = { open: { type: Boolean, default: false } }

  toggle() {
    this.openValue = !this.openValue
  }

  openValueChanged() {
    this.contentTarget.classList.toggle(this.hiddenClass, !this.openValue)
  }
}
<div data-controller="toggle" data-toggle-hidden-class="hidden">
  <button data-action="toggle#toggle">Toggle</button>
  <div data-toggle-target="content">Content here</div>
</div>

Turbo Frame Basics

<turbo-frame id="messages">
  <%= render @messages %>
</turbo-frame>

<%= link_to "Load more", messages_path(page: 2), data: { turbo_frame: "messages" } %>

Turbo Stream Basics

<%# app/views/messages/create.turbo_stream.erb %>
<%= turbo_stream.prepend "messages", @message %>
<%= turbo_stream.update "message_count", Message.count %>

Integration Tips

Rails View Helpers

<%# Stimulus data attributes %>
<%= tag.div data: { controller: "dropdown", dropdown_open_value: false } do %>
  ...
<% end %>

<%# Turbo frame %>
<%= turbo_frame_tag "user_#{user.id}" do %>
  <%= render user %>
<% end %>

Prevent Turbo on Specific Links

<%= link_to "Download", file_path, data: { turbo: false } %>
<%= link_to "External", "https://example.com", data: { turbo_frame: "_top" } %>