{"data":{"slug":"discovered-4d6455294e3138a317ea2b22a20d21d11bbe67fb7b79908e","title":"Rails 7+ Specialist for Active Record Optimization, Turbo Frames, Action Cable, Sidekiq, and RSpec Testing","summary":"Builds Rails 7+ web applications with Hotwire, real-time features, and background job processing. Delivers optimized Active Record queries, Turbo Frames\/Streams for partial page updates, Action Cable for WebSocket connections, Sidekiq workers for background jobs, and comprehensive RSpec test suites.","url":"https:\/\/skillshunter.net\/skills\/discovered-4d6455294e3138a317ea2b22a20d21d11bbe67fb7b79908e","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/discovered-4d6455294e3138a317ea2b22a20d21d11bbe67fb7b79908e","markdown_url":"https:\/\/skillshunter.net\/skills\/discovered-4d6455294e3138a317ea2b22a20d21d11bbe67fb7b79908e.md","download_url":"https:\/\/skillshunter.net\/skills\/discovered-4d6455294e3138a317ea2b22a20d21d11bbe67fb7b79908e\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Ensure Rails 7+ environment is set up with Hotwire, Active Record, Sidekiq, and RSpec. Run `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. Use `includes`\/`eager_load` to prevent N+1 queries and add database indexes for columns used in `WHERE`, `ORDER BY`, or `JOIN`.","instructions":"---\nname: rails-expert\ndescription: 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.\nlicense: MIT\nmetadata:\n  author: https:\/\/github.com\/Jeffallan\n  company: https:\/\/synergetic.solutions\n  version: \"1.1.0\"\n  domain: backend\n  triggers: Rails, Ruby on Rails, Hotwire, Turbo Frames, Turbo Streams, Action Cable, Active Record, Sidekiq, RSpec Rails\n  role: specialist\n  scope: implementation\n  output-format: code\n  related-skills: fullstack-guardian, database-optimizer\n---\n\n# Rails Expert\n\n## Core Workflow\n\n1. **Analyze requirements** \u2014 Identify models, routes, real-time needs, background jobs\n2. **Scaffold resources** \u2014 `rails generate model User name:string email:string`, `rails generate controller Users`\n3. **Run migrations** \u2014 `rails db:migrate` and verify schema with `rails db:schema:dump`\n   - If migration fails: inspect `db\/schema.rb` for conflicts, rollback with `rails db:rollback`, fix and retry\n4. **Implement** \u2014 Write controllers, models, add Hotwire (see Reference Guide below)\n5. **Validate** \u2014 `bundle exec rspec` must pass; `bundle exec rubocop` for style\n   - If specs fail: check error output, fix failing examples, re-run with `--format documentation` for detail\n   - If N+1 queries surface during review: add `includes`\/`eager_load` (see Common Patterns) and re-run specs\n6. **Optimize** \u2014 Audit for N+1 queries, add missing indexes, add caching\n\n## Reference Guide\n\nLoad detailed guidance based on context:\n\n| Topic | Reference | Load When |\n|-------|-----------|-----------|\n| Hotwire\/Turbo | `references\/hotwire-turbo.md` | Turbo Frames, Streams, Stimulus controllers |\n| Active Record | `references\/active-record.md` | Models, associations, queries, performance |\n| Background Jobs | `references\/background-jobs.md` | Sidekiq, job design, queues, error handling |\n| Testing | `references\/rspec-testing.md` | Model\/request\/system specs, factories |\n| API Development | `references\/api-development.md` | API-only mode, serialization, authentication |\n\n## Common Patterns\n\n### N+1 Prevention with includes\/eager_load\n\n```ruby\n# BAD \u2014 triggers N+1\nposts = Post.all\nposts.each { |post| puts post.author.name }\n\n# GOOD \u2014 eager load association\nposts = Post.includes(:author).all\nposts.each { |post| puts post.author.name }\n\n# GOOD \u2014 eager_load forces a JOIN (useful when filtering on association)\nposts = Post.eager_load(:author).where(authors: { verified: true })\n```\n\n### Turbo Frame Setup (partial page update)\n\n```erb\n<%# app\/views\/posts\/index.html.erb %>\n<%= turbo_frame_tag \"posts\" do %>\n  <%= render @posts %>\n  <%= link_to \"Load More\", posts_path(page: @next_page) %>\n<% end %>\n\n<%# app\/views\/posts\/_post.html.erb %>\n<%= turbo_frame_tag dom_id(post) do %>\n  <h2><%= post.title %><\/h2>\n  <%= link_to \"Edit\", edit_post_path(post) %>\n<% end %>\n```\n\n```ruby\n# app\/controllers\/posts_controller.rb\ndef index\n  @posts = Post.includes(:author).page(params[:page])\n  @next_page = @posts.next_page\nend\n```\n\n### Sidekiq Worker Template\n\n```ruby\n# app\/jobs\/send_welcome_email_job.rb\nclass SendWelcomeEmailJob < ApplicationJob\n  queue_as :default\n  sidekiq_options retry: 3, dead: false\n\n  def perform(user_id)\n    user = User.find(user_id)\n    UserMailer.welcome(user).deliver_now\n  rescue ActiveRecord::RecordNotFound => e\n    Rails.logger.warn(\"SendWelcomeEmailJob: user #{user_id} not found \u2014 #{e.message}\")\n    # Do not re-raise; record is gone, no point retrying\n  end\nend\n\n# Enqueue from controller or model callback\nSendWelcomeEmailJob.perform_later(user.id)\n```\n\n### Strong Parameters (controller template)\n\n```ruby\n# app\/controllers\/posts_controller.rb\nclass PostsController < ApplicationController\n  before_action :set_post, only: %i[show edit update destroy]\n\n  def create\n    @post = Post.new(post_params)\n    if @post.save\n      redirect_to @post, notice: \"Post created.\"\n    else\n      render :new, status: :unprocessable_entity\n    end\n  end\n\n  private\n\n  def set_post\n    @post = Post.find(params[:id])\n  end\n\n  def post_params\n    params.require(:post).permit(:title, :body, :published_at)\n  end\nend\n```\n\n## Constraints\n\n### MUST DO\n- Prevent N+1 queries with `includes`\/`eager_load` on every collection query involving associations\n- Write comprehensive specs targeting >95% coverage\n- Use service objects for complex business logic; keep controllers thin\n- Add database indexes for every column used in `WHERE`, `ORDER BY`, or `JOIN`\n- Offload slow operations to Sidekiq \u2014 never run them synchronously in a request cycle\n\n### MUST NOT DO\n- Skip migrations for schema changes\n- Use raw SQL without sanitization (`sanitize_sql` or parameterized queries only)\n- Expose internal IDs in URLs without consideration\n\n## Output Templates\n\nWhen implementing Rails features, provide:\n1. Migration file (if schema changes needed)\n2. Model file with associations and validations\n3. Controller with RESTful actions and strong parameters\n4. View files or Hotwire setup\n5. Spec files for models and requests\n6. Brief explanation of architectural decisions\n\nMaintained by [@jeffallan](https:\/\/github.com\/jeffallan), Principal Consultant at [Synergetic Solutions](https:\/\/synergetic.solutions)\n\n[Documentation](https:\/\/jeffallan.github.io\/claude-skills\/skills\/backend\/rails-expert\/)\n","use_cases":["Implement Turbo Frames\/Streams for partial page updates","Configure Action Cable for real-time WebSocket connections","Set up Sidekiq workers for background job processing","Write comprehensive RSpec test suites for Rails 7+ applications","Optimize Active Record queries using `includes`\/`eager_load` and add database indexes"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/Jeffallan\/claude-skills\/blob\/a8be463010e2ca23afe00ea00773aea7128e8971\/plugin\/skills\/rails-expert\/SKILL.md","source_commit":"a8be463010e2ca23afe00ea00773aea7128e8971","license":null,"version":null,"listing_approved_at":"2026-11-29","created_at":"2026-11-28T18:47:48.000000Z","updated_at":"2026-11-29T10:53:27.000000Z","seo_title":"Rails 7+ Specialist for Active Record, Turbo, Action Cable, Sidekiq, R","seo_description":"A Rails 7+ specialist that optimizes Active Record queries, implements Turbo Frames and Streams, configures Action Cable, sets up Sidekiq workers, and writes RSpec test","seo_keywords":["Rails 7","Active Record optimization","Turbo Frames","Turbo Streams","Action Cable","Sidekiq","RSpec Rails","Hotwire"]}}