Skip to main content

hotwire

Hotwire, Turbo, and Stimulus patterns for Rails. Use when implementing JavaScript interactions, Turbo Frames/Streams, or Stimulus controllers. Triggers on "stimulus controller", "turbo frame", "turbo stream", "hotwire", "rails javascript".

소스 정보

저장소
bibendi/starmap
최근 소스 활동
2026년 3월 30일 21:08
감지된 SKILL.md 언어
영어
스타
4
포크
0

설치 방법

기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.

소스 파일 검토

설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.

SKILL.md 표시 중

SKILL.md
소스 지침 · 읽기 전용 미리보기
name
hotwire
description
Hotwire, Turbo, and Stimulus patterns for Rails. Use when implementing JavaScript interactions, Turbo Frames/Streams, or Stimulus controllers. Triggers on "stimulus controller", "turbo frame", "turbo stream", "hotwire", "rails javascript".
# Hotwire, Turbo & Stimulus for Rails Expert patterns for JavaScript and Hotwire integration with Ruby on Rails. ## Core Principles 1. Use latest versions based on Gemfile 2. Follow Rails conventions and best practices 3. Use Context7 MCP or hotwire.dev for documentation 4. Test JavaScript with Vitest (./test/controllers) 5. Review existing Stimulus controllers before creating new ones ## Stimulus Controllers ### Guidelines - Keep controllers simple and focused - Make controllers generic when possible, specific only when needed - **Never** have controllers communicate with each other - Integrate into ERB templates using Rails conventions ### Structure ```javascript // app/javascript/controllers/toggle_controller.js import { Controller } from "@hotwired/stimulus" export default class extends Controller { static targets = ["content"] static values = { open: Boolean } toggle() { this.openValue = !this.openValue } openValueChanged() { this.contentTarget.classList.toggle("hidden", !this.openValue) } } ``` ### ERB Integration ```erb <div data-controller="toggle" data-toggle-open-value="false"> <button data-action="toggle#toggle">Toggle</button> <div data-toggle-target="content" class="hidden"> Content here </div> </div> ``` ## Turbo Frames Use for partial page updates without full refreshes. ```erb <%= turbo_frame_tag "user_profile" do %> <%= render @user %> <% end %> <!-- Link that updates only the frame --> <%= link_to "Edit", edit_user_path(@user), data: { turbo_frame: "user_profile" } %> ``` ## Turbo Streams Use for real-time updates from server. ```ruby # Controller respond_to do |format| format.turbo_stream format.html { redirect_to @post } end ``` ```erb <%# app/views/posts/create.turbo_stream.erb %> <%= turbo_stream.prepend "posts", @post %> <%= turbo_stream.update "post_count", Post.count %> ``` ## AJAX Requests Use `request.js` for AJAX when needed: ```javascript import { get, post } from "@rails/request.js" async function loadData() { const response = await get("/api/data", { responseKind: "json" }) if (response.ok) { const data = await response.json // handle data } } ``` ## Import Maps Include JavaScript libraries via import maps. Only add libraries when absolutely necessary. ```ruby # config/importmap.rb pin "lodash", to: "https://ga.jspm.io/npm:lodash@4.17.21/lodash.js" ``` If import maps aren't used, follow whatever asset pipeline the application uses.
GitHub에서 보기