一键导入
ruby-rails
Use for Rails apps: ActiveRecord/models, migrations, controllers/routes, background jobs, caching, and Hotwire. Not for non-Rails Ruby.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use for Rails apps: ActiveRecord/models, migrations, controllers/routes, background jobs, caching, and Hotwire. Not for non-Rails Ruby.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | ruby-rails |
| description | Use for Rails apps: ActiveRecord/models, migrations, controllers/routes, background jobs, caching, and Hotwire. Not for non-Rails Ruby. |
Idiomatic Rails development — conventions, ActiveRecord, and production patterns.
class AddEmailVerifiedToUsers < ActiveRecord::Migration[7.1]
def change
# Step 1: nullable column (safe to deploy before backfill)
add_column :users, :email_verified, :boolean
# Step 2: backfill in batches to avoid full-table lock
User.in_batches.update_all(email_verified: false)
# Step 3: enforce the constraint after backfill completes
change_column_null :users, :email_verified, false, false
change_column_default :users, :email_verified, false
end
end
Always add indexes alongside foreign keys and query predicates. Use add_index :orders, :customer_id in the same migration as the column.
class Order < ApplicationRecord
belongs_to :customer
has_many :items, dependent: :destroy
# Composable scopes — chain freely without N+1
scope :recent, -> { order(created_at: :desc) }
scope :for_customer, ->(id) { where(customer_id: id) }
scope :pending, -> { where(status: :pending) }
scope :with_details, -> { includes(:items, :customer) }
# Enum for finite states — generates predicates like order.pending?
enum :status, { pending: 0, confirmed: 1, shipped: 2, delivered: 3 }
validates :customer, presence: true
validates :status, presence: true
end
Controller stays thin — it composes scopes, it doesn't implement business logic:
class OrdersController < ApplicationController
def index
@orders = Order.with_details.recent.for_customer(params[:customer_id])
end
def create
@order = Order.new(order_params)
if @order.save
redirect_to @order, notice: "Order created"
else
render :new, status: :unprocessable_entity
end
end
private
def order_params
params.require(:order).permit(:customer_id, :notes, items_attributes: [:product_id, :quantity])
end
end
class ProcessOrderJob < ApplicationJob
queue_as :default
retry_on ActiveRecord::Deadlocked, wait: 5.seconds, attempts: 3
discard_on ActiveRecord::RecordNotFound
def perform(order_id)
order = Order.find_by(id: order_id)
return unless order&.pending? # Idempotent guard — safe to re-run
ActiveRecord::Base.transaction do
order.confirm!
InventoryService.reserve(order)
end
OrderMailer.confirmation(order).deliver_later
end
end
Pass IDs, not full objects — Active Job serializes records by ID and re-loads on execution to avoid stale data.
# Fragment caching with automatic expiry via cache_key_with_version
<% cache @order do %>
<%= render @order %>
<% end %>
# Russian-doll: parent key changes when child changes
<% cache [@customer, @customer.orders.maximum(:updated_at)] do %>
<% @customer.orders.each do |order| %>
<% cache order do %><%= render order %><% end %>
<% end %>
<% end %>
For low-traffic read-heavy data, use Rails.cache.fetch:
def self.featured
Rails.cache.fetch("products/featured", expires_in: 1.hour) do
where(featured: true).with_details.to_a
end
end
includes (or preload/eager_load) for associations rendered in views or serializers; use Bullet gem to catch them in developmentadd_index :users, :email, unique: true and foreign key constraints at the DB leveldependent: :destroy on large associations triggers callbacks for every record — use dependent: :delete_all or schedule a background cleanup job for tables with millions of rowsupdate_all and delete_all skip callbacks and validations — use find_each { |r| r.update(...) } when callbacks matter, but be aware of the performance tradeoff{ "_aj_globalid": "gid://..." } and re-query on load; if the record is deleted before the job runs, it raises unless you discard_on ActiveRecord::RecordNotFoundUse when implementing real-time DSP algorithms, audio thread architecture, or offline spectral analysis in C++/Rust. Covers filters, STFT pipelines, lock-free concurrency, and RT safety. Not for JUCE plugin lifecycle wiring or ffmpeg.
Use for real-time audio code safety, determinism, and numeric hygiene. Required foundation for DSP, audio analysis, audio systems, and JUCE work. Not for game-audio middleware or ffmpeg/video tasks.
Use when programmatically processing video/audio with libffmpeg C API. Not for command-line ffmpeg operations.
Use for JUCE audio apps/plugins: AudioProcessor lifecycle, VST3/AU targets, parameter systems, and thread separation. Requires audio-engineering-principles. Not for game-audio middleware or non-JUCE frameworks.
Use when writing, reviewing, or refactoring C++ code — covers workflow, essential patterns, and pre-commit checklist for modern C++17/20.
Use when writing or fixing C++ tests, configuring GoogleTest/CTest, or adding coverage/sanitizers.