rails
Ruby on Railsは、設定よりも規約を重視したWebフレームワークで、データベース連携や画面表示、リアルタイム通信などの機能と、開発を効率化する機能が備わっており、迅速なWebアプリケーション開発を支援するSkill。
📜 元の英語説明(参考)
Ruby on Rails is a full-stack web framework following convention over configuration. It provides ActiveRecord ORM, Action Controller, Action View templates, Action Cable for WebSockets, and generators for rapid application development.
🇯🇵 日本人クリエイター向け解説
Ruby on Railsは、設定よりも規約を重視したWebフレームワークで、データベース連携や画面表示、リアルタイム通信などの機能と、開発を効率化する機能が備わっており、迅速なWebアプリケーション開発を支援するSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o rails.zip https://jpskill.com/download/15314.zip && unzip -o rails.zip && rm rails.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/15314.zip -OutFile "$d\rails.zip"; Expand-Archive "$d\rails.zip" -DestinationPath $d -Force; ri "$d\rails.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
rails.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
railsフォルダができる - 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 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
Ruby on Rails
Rails は、設定よりも規約を重視する、独自の考え方を持つフルスタックフレームワークです。データベースをバックエンドとする Web アプリケーションを構築するために必要なものすべて(ORM、ルーティング、ビュー、メーラー、ジョブ、および WebSocket のサポート)が含まれています。
インストール
# PostgreSQL を使用した新しい Rails アプリケーションの作成
gem install rails
rails new myapp --database=postgresql --css=tailwind
cd myapp
rails db:create
プロジェクト構造
# 標準的な Rails プロジェクトのレイアウト
app/
├── controllers/ # リクエストハンドラ
├── models/ # ActiveRecord モデル
├── views/ # ERB/HTML テンプレート
├── channels/ # Action Cable チャンネル
├── jobs/ # バックグラウンドジョブ
├── mailers/ # メールクラス
└── serializers/ # API シリアライザ
config/
├── routes.rb # URL ルーティング
├── database.yml # DB 設定
└── environments/ # 環境ごとの設定
db/
├── migrate/ # スキーママイグレーション
├── schema.rb # 現在のスキーマ
└── seeds.rb # シードデータ
モデル
# app/models/article.rb — ActiveRecord モデル
class Article < ApplicationRecord
belongs_to :author, class_name: "User"
has_many :comments, dependent: :destroy
validates :title, presence: true, length: { maximum: 200 }
validates :slug, presence: true, uniqueness: true
validates :body, presence: true
scope :published, -> { where(published: true) }
scope :recent, -> { order(created_at: :desc) }
before_validation :generate_slug, on: :create
private
def generate_slug
self.slug = title&.parameterize
end
end
マイグレーション
# db/migrate/20240101000000_create_articles.rb — データベースマイグレーション
class CreateArticles < ActiveRecord::Migration[7.1]
def change
create_table :articles do |t|
t.string :title, null: false, limit: 200
t.string :slug, null: false, index: { unique: true }
t.text :body, null: false
t.references :author, null: false, foreign_key: { to_table: :users }
t.boolean :published, default: false
t.timestamps
end
end
end
コントローラ
# app/controllers/articles_controller.rb — RESTful コントローラ
class ArticlesController < ApplicationController
before_action :authenticate_user!, except: [:index, :show]
before_action :set_article, only: [:show, :update, :destroy]
def index
@articles = Article.published.recent
.includes(:author)
.page(params[:page])
.per(20)
render json: @articles, include: [:author]
end
def show
render json: @article
end
def create
@article = current_user.articles.build(article_params)
if @article.save
render json: @article, status: :created
else
render json: { errors: @article.errors }, status: :unprocessable_entity
end
end
def destroy
@article.destroy
head :no_content
end
private
def set_article
@article = Article.find(params[:id])
end
def article_params
params.require(:article).permit(:title, :body)
end
end
ルーティング
# config/routes.rb — URL ルーティング
Rails.application.routes.draw do
root "pages#home"
resources :articles, only: [:index, :show, :create, :update, :destroy]
namespace :api do
namespace :v1 do
resources :articles, only: [:index, :show]
end
end
mount ActionCable.server => "/cable"
end
ビュー
<!-- app/views/articles/index.html.erb — リストビューテンプレート -->
<h1>Articles</h1>
<% @articles.each do |article| %>
<article>
<h2><%= link_to article.title, article_path(article) %></h2>
<p>By <%= article.author.name %> — <%= time_ago_in_words(article.created_at) %> ago</p>
<p><%= truncate(article.body, length: 200) %></p>
</article>
<% end %>
<%= paginate @articles %>
Action Cable (WebSockets)
# app/channels/chat_channel.rb — WebSocket チャンネル
class ChatChannel < ApplicationCable::Channel
def subscribed
stream_from "chat_#{params[:room_id]}"
end
def receive(data)
ActionCable.server.broadcast("chat_#{params[:room_id]}", {
user: current_user.name,
message: data["message"]
})
end
end
バックグラウンドジョブ
# app/jobs/send_notification_job.rb — Active Job
class SendNotificationJob < ApplicationJob
queue_as :default
retry_on StandardError, wait: :polynomially_longer, attempts: 5
def perform(user, message)
NotificationService.send(user, message)
end
end
# エンキュー: SendNotificationJob.perform_later(user, "Hello!")
テスト
# test/models/article_test.rb — モデルテスト
require "test_helper"
class ArticleTest < ActiveSupport::TestCase
test "validates title presence" do
article = Article.new(body: "content", author: users(:one))
assert_not article.valid?
assert_includes article.errors[:title], "can't be blank"
end
test "published scope" do
assert_includes Article.published, articles(:published_one)
assert_not_includes Article.published, articles(:draft_one)
end
end
主要なコマンド
# 一般的な Rails コマンド
rails generate model Article title:string body:text author:references
rails generate controller Articles index show create
rails db:migrate
rails db:seed
rails console # インタラクティブ REPL
rails routes # すべてのルートを表示
rails test # テストの実行
主要なパターン
strong_parameters(params.permit) を使用して入力をホワイトリスト化します。ユーザーデータを決して信用しないでください。includes/eager_loadを使用して N+1 クエリを防ぎます。- モデルで再利用可能なクエリロジックにスコープを使用します。
- 認証とリソースのロードに
before_actionを使用します。 - バックグラウンド処理には Active Job + Sidekiq/GoodJob を使用します。
- シークレットには
rails credentials:editを使用します。決してコミットしないでください。
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Ruby on Rails
Rails is an opinionated full-stack framework that favors convention over configuration. It includes everything needed to build database-backed web apps: ORM, routing, views, mailers, jobs, and WebSocket support.
Installation
# Create new Rails app with PostgreSQL
gem install rails
rails new myapp --database=postgresql --css=tailwind
cd myapp
rails db:create
Project Structure
# Standard Rails project layout
app/
├── controllers/ # Request handlers
├── models/ # ActiveRecord models
├── views/ # ERB/HTML templates
├── channels/ # Action Cable channels
├── jobs/ # Background jobs
├── mailers/ # Email classes
└── serializers/ # API serializers
config/
├── routes.rb # URL routing
├── database.yml # DB config
└── environments/ # Per-env settings
db/
├── migrate/ # Schema migrations
├── schema.rb # Current schema
└── seeds.rb # Seed data
Models
# app/models/article.rb — ActiveRecord model
class Article < ApplicationRecord
belongs_to :author, class_name: "User"
has_many :comments, dependent: :destroy
validates :title, presence: true, length: { maximum: 200 }
validates :slug, presence: true, uniqueness: true
validates :body, presence: true
scope :published, -> { where(published: true) }
scope :recent, -> { order(created_at: :desc) }
before_validation :generate_slug, on: :create
private
def generate_slug
self.slug = title&.parameterize
end
end
Migrations
# db/migrate/20240101000000_create_articles.rb — database migration
class CreateArticles < ActiveRecord::Migration[7.1]
def change
create_table :articles do |t|
t.string :title, null: false, limit: 200
t.string :slug, null: false, index: { unique: true }
t.text :body, null: false
t.references :author, null: false, foreign_key: { to_table: :users }
t.boolean :published, default: false
t.timestamps
end
end
end
Controllers
# app/controllers/articles_controller.rb — RESTful controller
class ArticlesController < ApplicationController
before_action :authenticate_user!, except: [:index, :show]
before_action :set_article, only: [:show, :update, :destroy]
def index
@articles = Article.published.recent
.includes(:author)
.page(params[:page])
.per(20)
render json: @articles, include: [:author]
end
def show
render json: @article
end
def create
@article = current_user.articles.build(article_params)
if @article.save
render json: @article, status: :created
else
render json: { errors: @article.errors }, status: :unprocessable_entity
end
end
def destroy
@article.destroy
head :no_content
end
private
def set_article
@article = Article.find(params[:id])
end
def article_params
params.require(:article).permit(:title, :body)
end
end
Routes
# config/routes.rb — URL routing
Rails.application.routes.draw do
root "pages#home"
resources :articles, only: [:index, :show, :create, :update, :destroy]
namespace :api do
namespace :v1 do
resources :articles, only: [:index, :show]
end
end
mount ActionCable.server => "/cable"
end
Views
<!-- app/views/articles/index.html.erb — list view template -->
<h1>Articles</h1>
<% @articles.each do |article| %>
<article>
<h2><%= link_to article.title, article_path(article) %></h2>
<p>By <%= article.author.name %> — <%= time_ago_in_words(article.created_at) %> ago</p>
<p><%= truncate(article.body, length: 200) %></p>
</article>
<% end %>
<%= paginate @articles %>
Action Cable (WebSockets)
# app/channels/chat_channel.rb — WebSocket channel
class ChatChannel < ApplicationCable::Channel
def subscribed
stream_from "chat_#{params[:room_id]}"
end
def receive(data)
ActionCable.server.broadcast("chat_#{params[:room_id]}", {
user: current_user.name,
message: data["message"]
})
end
end
Background Jobs
# app/jobs/send_notification_job.rb — Active Job
class SendNotificationJob < ApplicationJob
queue_as :default
retry_on StandardError, wait: :polynomially_longer, attempts: 5
def perform(user, message)
NotificationService.send(user, message)
end
end
# Enqueue: SendNotificationJob.perform_later(user, "Hello!")
Testing
# test/models/article_test.rb — model test
require "test_helper"
class ArticleTest < ActiveSupport::TestCase
test "validates title presence" do
article = Article.new(body: "content", author: users(:one))
assert_not article.valid?
assert_includes article.errors[:title], "can't be blank"
end
test "published scope" do
assert_includes Article.published, articles(:published_one)
assert_not_includes Article.published, articles(:draft_one)
end
end
Key Commands
# Common Rails commands
rails generate model Article title:string body:text author:references
rails generate controller Articles index show create
rails db:migrate
rails db:seed
rails console # Interactive REPL
rails routes # Show all routes
rails test # Run tests
Key Patterns
- Use
strong_parameters(params.permit) to whitelist input — never trust user data - Use
includes/eager_loadto prevent N+1 queries - Use scopes for reusable query logic on models
- Use
before_actionfor authentication and resource loading - Use Active Job + Sidekiq/GoodJob for background processing
- Use
rails credentials:editfor secrets — never commit them