‹ 首页

rails-expert

@jeffallan · 收录于 1 周前 · 上游提交 1 个月前

Rails 7+ specialist that optimizes Active Record queries with includes/eager_load, implements Turbo Frames and Turbo Streams for partial page updates, configures Action Cable for WebSocket connections, sets up Sidekiq workers for background job processing, and writes comprehensive RSpec test suites. Use when building Rails 7+ web applications with Hotwire, real-time features, or background job processing. Invoke for Active Record optimization, Turbo Frames/Streams, Action Cable, Sidekiq, RSpec Rails.

适合你,如果正在用 Rails 7+ 构建含实时特性的 Web 应用

/ 下载安装
rails-expert.skill双击,或拖进 Claude 桌面版 / Cowork,即完成安装↓ .skill↓ .zip
用别的 agent?下载 .zip 解压,把文件夹放进它的技能目录
Claude Code~/.claude/skills/(项目级 .claude/skills/)
Codex CLI~/.codex/skills/
Cursor自动读取上面两处目录
其他工具见其文档的「skills」目录;两个下载是同一份文件,只是名字不同
/ 通过 npx 安装 校验哈希
npx oh-my-skill add jeffallan/claude-skills/rails-expert
/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- jeffallan/claude-skills/rails-expert
/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify jeffallan/claude-skills/rails-expert
安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
10501GitHub stars
~1.1K最小装载
~7.4K含声明引用
~7.4K文本包总量
镜像托管

怎么用

商店整理自技能原文 · 版本 e8be415 · 表述以原文为准
它做什么

Claude 会帮你写 Rails 7+ 代码,包括优化数据库查询、实现页面局部更新、配置 WebSocket、设置后台任务和编写测试。

什么时候触发

当你提到 Rails、Hotwire、Turbo Frames、Sidekiq 等关键词,或要求处理数据库优化、实时功能、后台任务时触发。

装好后可以这样说
Claude 会生成视图和控制器代码。
Claude 会创建 Job 文件和调用示例。
技能原文 SKILL.md作者撰写 · MIT · e8be415

Rails Expert

Core Workflow
  1. Analyze requirements — Identify models, routes, real-time needs, background jobs
  2. Scaffold resourcesrails generate model User name:string email:string, rails generate controller Users
  3. Run migrationsrails db:migrate and verify schema with rails db:schema:dump
  4. If migration fails: inspect db/schema.rb for conflicts, rollback with rails db:rollback, fix and retry
  5. Implement — Write controllers, models, add Hotwire (see Reference Guide below)
  6. Validatebundle exec rspec must pass; bundle exec rubocop for style
  7. If specs fail: check error output, fix failing examples, re-run with --format documentation for detail
  8. If N+1 queries surface during review: add includes/eager_load (see Common Patterns) and re-run specs
  9. Optimize — Audit for N+1 queries, add missing indexes, add caching
Reference Guide

Load detailed guidance based on context:

| Topic | Reference | Load When | |-------|-----------|-----------| | Hotwire/Turbo | references/hotwire-turbo.md | Turbo Frames, Streams, Stimulus controllers | | Active Record | references/active-record.md | Models, associations, queries, performance | | Background Jobs | references/background-jobs.md | Sidekiq, job design, queues, error handling | | Testing | references/rspec-testing.md | Model/request/system specs, factories | | API Development | references/api-development.md | API-only mode, serialization, authentication |

Common Patterns
N+1 Prevention with includes/eager_load
# BAD — triggers N+1
posts = Post.all
posts.each { |post| puts post.author.name }

# GOOD — eager load association
posts = Post.includes(:author).all
posts.each { |post| puts post.author.name }

# GOOD — eager_load forces a JOIN (useful when filtering on association)
posts = Post.eager_load(:author).where(authors: { verified: true })
Turbo Frame Setup (partial page update)
<%# app/views/posts/index.html.erb %>
<%= turbo_frame_tag "posts" do %>
  <%= render @posts %>
  <%= link_to "Load More", posts_path(page: @next_page) %>
<% end %>

<%# app/views/posts/_post.html.erb %>
<%= turbo_frame_tag dom_id(post) do %>
  <h2><%= post.title %></h2>
  <%= link_to "Edit", edit_post_path(post) %>
<% end %>
# app/controllers/posts_controller.rb
def index
  @posts = Post.includes(:author).page(params[:page])
  @next_page = @posts.next_page
end
Sidekiq Worker Template
# app/jobs/send_welcome_email_job.rb
class SendWelcomeEmailJob < ApplicationJob
  queue_as :default
  sidekiq_options retry: 3, dead: false

  def perform(user_id)
    user = User.find(user_id)
    UserMailer.welcome(user).deliver_now
  rescue ActiveRecord::RecordNotFound => e
    Rails.logger.warn("SendWelcomeEmailJob: user #{user_id} not found — #{e.message}")
    # Do not re-raise; record is gone, no point retrying
  end
end

# Enqueue from controller or model callback
SendWelcomeEmailJob.perform_later(user.id)
Strong Parameters (controller template)
# app/controllers/posts_controller.rb
class PostsController < ApplicationController
  before_action :set_post, only: %i[show edit update destroy]

  def create
    @post = Post.new(post_params)
    if @post.save
      redirect_to @post, notice: "Post created."
    else
      render :new, status: :unprocessable_entity
    end
  end

  private

  def set_post
    @post = Post.find(params[:id])
  end

  def post_params
    params.require(:post).permit(:title, :body, :published_at)
  end
end
Constraints
MUST DO
  • Prevent N+1 queries with includes/eager_load on every collection query involving associations
  • Write comprehensive specs targeting >95% coverage
  • Use service objects for complex business logic; keep controllers thin
  • Add database indexes for every column used in WHERE, ORDER BY, or JOIN
  • Offload slow operations to Sidekiq — never run them synchronously in a request cycle
MUST NOT DO
  • Skip migrations for schema changes
  • Use raw SQL without sanitization (sanitize_sql or parameterized queries only)
  • Expose internal IDs in URLs without consideration
Output Templates

When implementing Rails features, provide:

  1. Migration file (if schema changes needed)
  2. Model file with associations and validations
  3. Controller with RESTful actions and strong parameters
  4. View files or Hotwire setup
  5. Spec files for models and requests
  6. Brief explanation of architectural decisions

Documentation

按 MIT 许可原样转载,未经改动 · 在 GitHub 查看 →

评论

登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。