Langsung ke konten
Skillpedia
API & server (backend)12k Β· #11449

rails-expert

Fungsinya

Skill ini memandu agent AI untuk membangun aplikasi web dengan Ruby on Rails 7 ke atas. Skill ini untuk pengembang yang membangun aplikasi Rails dengan pembaruan langsung dan pekerjaan latar belakang.

Kapan dipakai

  • βœ“Saat Anda membangun aplikasi Rails 7 dengan Hotwire, Turbo Frame, atau Turbo Stream.
  • βœ“Saat Anda membutuhkan job latar belakang dengan Sidekiq atau fitur real-time dengan Action Cable.
  • βœ“Saat query Active Record menimbulkan masalah N+1 dan perlu diperbaiki.

Link skill

https://github.com/Jeffallan/claude-skills/blob/main/skills/rails-expert/SKILL.md

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/Jeffallan/claude-skills/blob/main/skills/rails-expert/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit β†’

Contoh permintaan ke AI

β€œBangun papan tugas Rails 7 dengan pembaruan langsung memakai Turbo Stream dan job Sidekiq untuk pengingat email.”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Agent membuat model dan controller, menambahkan Hotwire untuk pembaruan sebagian halaman, dan menyiapkan job latar belakang. Setelah itu agent menjalankan RSpec dan RuboCop untuk memeriksa hasilnya.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.

Rails Expert

Core Workflow

  1. Analyze requirements β€” Identify models, routes, real-time needs, background jobs
  2. Scaffold resources β€” rails generate model User name:string email:string, rails generate controller Users
  3. Run migrations β€” rails db:migrate and verify schema with rails db:schema:dump
    • If migration fails: inspect db/schema.rb for conflicts, rollback with rails db:rollback, fix and retry
  4. Implement β€” Write controllers, models, add Hotwire (see Reference Guide below)
  5. Validate β€” bundle exec rspec must pass; bundle exec rubocop for style
    • If specs fail: check error output, fix failing examples, re-run with --format documentation for detail
    • If N+1 queries surface during review: add includes/eager_load (see Common Patterns) and re-run specs
  6. 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 de
Pertanyaan umum

Bagaimana skill ini memperbaiki query database yang lambat?

Skill ini menambahkan includes atau eager_load untuk menghilangkan query N+1, dan bisa menambahkan indeks yang belum ada.

Framework tes apa yang dipakai?

Skill ini menulis spec model, request, dan sistem dengan RSpec.

Apakah caching juga dicakup?

Ya. Skill ini menambahkan caching di tempat yang membantu mempercepat halaman.

Detail

Deskripsi asli dari pembuat

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.

repo: Jeffallan/claude-skills

Popularitas

Bintang GitHub
12k
Peringkat
#11449
Lisensi
MIT
Diperbarui
30/10/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa