rails-controller-patterns
Railsのコントローラー、ルーティング、ストロングパラメータ、アクション前処理など、Rails開発における一般的なパターンや規約を理解し、効率的な開発を支援するSkill。
📜 元の英語説明(参考)
Rails controller patterns and conventions. Automatically invoked when working with controllers, routes, strong parameters, before_actions, or request handling. Triggers on "controller", "action", "routes", "routing", "strong params", "params.expect", "before_action", "respond_to", "RESTful", "CRUD", "redirect", "render".
🇯🇵 日本人クリエイター向け解説
Railsのコントローラー、ルーティング、ストロングパラメータ、アクション前処理など、Rails開発における一般的なパターンや規約を理解し、効率的な開発を支援するSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o rails-controller-patterns.zip https://jpskill.com/download/10045.zip && unzip -o rails-controller-patterns.zip && rm rails-controller-patterns.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/10045.zip -OutFile "$d\rails-controller-patterns.zip"; Expand-Archive "$d\rails-controller-patterns.zip" -DestinationPath $d -Force; ri "$d\rails-controller-patterns.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
rails-controller-patterns.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
rails-controller-patternsフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
Rails Controller Patterns
適切に構造化された Rails コントローラを構築するためのパターンです。
この Skill が適用される場合
- RESTful なコントローラアクションの実装
- リクエストパラメータの安全な処理
before_actionフィルタの設定- レスポンスフォーマットの管理
- ルーティングの設計
- コントローラでのエラー処理
主要な原則
Thin Controllers
コントローラは以下を行うべきです。
- HTTP に関する処理(params、session、response)
- ビジネスロジックをモデル/サービスに委譲
- アクションを 10 行未満に保つ
RESTful Design
標準的な CRUD アクションに従ってください。
index、show、new、create、edit、update、destroy- カスタムアクションは控えめに追加
詳細なドキュメント
- patterns.md - コントローラのパターンと例
コントローラの構造
class PostsController < ApplicationController
# 1. Before actions
before_action :authenticate_user!
before_action :set_post, only: [:show, :edit, :update, :destroy]
# 2. Actions (CRUD order)
def index
@posts = Post.recent.page(params[:page])
end
def show
end
def new
@post = current_user.posts.build
end
def create
@post = current_user.posts.build(post_params)
if @post.save
redirect_to @post, notice: 'Post created.'
else
render :new, status: :unprocessable_entity
end
end
def edit
end
def update
if @post.update(post_params)
redirect_to @post, notice: 'Post updated.'
else
render :edit, status: :unprocessable_entity
end
end
def destroy
@post.destroy
redirect_to posts_path, notice: 'Post deleted.'
end
private
# 3. Private methods
def set_post
@post = current_user.posts.find(params[:id])
end
def post_params
params.expect(post: [:title, :content, :published])
end
end
Strong Parameters (Rails 8+)
# Rails 8+ syntax with expect
def post_params
params.expect(post: [:title, :content, tags: []])
end
# Nested attributes
def user_params
params.expect(user: [:name, :email, profile_attributes: [:bio, :avatar]])
end
# Traditional permit (still works)
def post_params
params.require(:post).permit(:title, :content, tags: [])
end
クイックリファレンス
| Action | HTTP Verb | Path | Purpose |
|---|---|---|---|
| index | GET | /posts | すべて一覧表示 |
| show | GET | /posts/:id | 1 つ表示 |
| new | GET | /posts/new | 新規作成フォーム |
| create | POST | /posts | 作成 |
| edit | GET | /posts/:id/edit | 編集フォーム |
| update | PATCH/PUT | /posts/:id | 更新 |
| destroy | DELETE | /posts/:id | 削除 |
主要な規約
- 成功した変更後には
redirect_toを使用します - バリデーションエラーの場合には
render :action, status: :unprocessable_entityを使用します - 適切な HTTP ステータスコードを返します
- private メソッドは最小限に保ちます
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Rails Controller Patterns
Patterns for building well-structured Rails controllers.
When This Skill Applies
- Implementing RESTful controller actions
- Handling request parameters safely
- Setting up before_action filters
- Managing response formats
- Designing routes
- Error handling in controllers
Core Principles
Thin Controllers
Controllers should:
- Handle HTTP concerns (params, session, response)
- Delegate business logic to models/services
- Keep actions under 10 lines
RESTful Design
Stick to standard CRUD actions:
index,show,new,create,edit,update,destroy- Add custom actions sparingly
Detailed Documentation
- patterns.md - Controller patterns and examples
Controller Structure
class PostsController < ApplicationController
# 1. Before actions
before_action :authenticate_user!
before_action :set_post, only: [:show, :edit, :update, :destroy]
# 2. Actions (CRUD order)
def index
@posts = Post.recent.page(params[:page])
end
def show
end
def new
@post = current_user.posts.build
end
def create
@post = current_user.posts.build(post_params)
if @post.save
redirect_to @post, notice: 'Post created.'
else
render :new, status: :unprocessable_entity
end
end
def edit
end
def update
if @post.update(post_params)
redirect_to @post, notice: 'Post updated.'
else
render :edit, status: :unprocessable_entity
end
end
def destroy
@post.destroy
redirect_to posts_path, notice: 'Post deleted.'
end
private
# 3. Private methods
def set_post
@post = current_user.posts.find(params[:id])
end
def post_params
params.expect(post: [:title, :content, :published])
end
end
Strong Parameters (Rails 8+)
# Rails 8+ syntax with expect
def post_params
params.expect(post: [:title, :content, tags: []])
end
# Nested attributes
def user_params
params.expect(user: [:name, :email, profile_attributes: [:bio, :avatar]])
end
# Traditional permit (still works)
def post_params
params.require(:post).permit(:title, :content, tags: [])
end
Quick Reference
| Action | HTTP Verb | Path | Purpose |
|---|---|---|---|
| index | GET | /posts | List all |
| show | GET | /posts/:id | Show one |
| new | GET | /posts/new | Form for new |
| create | POST | /posts | Create |
| edit | GET | /posts/:id/edit | Form for edit |
| update | PATCH/PUT | /posts/:id | Update |
| destroy | DELETE | /posts/:id | Delete |
Key Conventions
- Use
redirect_toafter successful changes - Use
render :action, status: :unprocessable_entityfor validation failures - Return appropriate HTTP status codes
- Keep private methods minimal