refactor-rails_skill

This skill refactors messy Rails code into maintainable, idiomatic solutions by applying SRP, DRY, and modern Ruby/Rails practices.

6

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill snakeo/claude-debug-and-refactor-skills-plugin --skill refactor-rails

  • SKILL.md12.4 KB

Overview

This skill refactors Ruby on Rails applications to improve maintainability, readability, and alignment with modern Rails and Ruby practices. It transforms fat controllers and models into small, focused classes using service objects, query objects, concerns, form objects, and decorators. The goal is working, well-tested code that follows SRP and Rails conventions.

How this skill works

I inspect code for smells: long methods, deep nesting, duplicated logic, N+1 queries, and mixed responsibilities. I propose and apply incremental refactors: extract services, queries, concerns, and decorators; replace callbacks with explicit services; introduce strong parameters and Turbo-friendly responses. Each change is small, tested, and reversible so the app stays functional during the process.

When to use it

  • Controllers or models longer than 100 lines or with many responsibilities
  • Repeated logic across models, controllers, or views
  • Complex database queries causing N+1s or poor performance
  • Large methods with deep nesting or unclear intent
  • When preparing code for new features or onboarding new team members

Best practices

  • Extract business logic to app/services and complex DB logic to app/queries
  • Keep controllers skinny: parse params, call services, handle responses
  • Use concerns for shared behavior and decorators for view logic
  • Apply guard clauses, small methods, and clear naming
  • Run tests and linters after each incremental change; keep commits small

Example use cases

  • Turn a 300-line OrdersController into a 15-line controller + Orders::CreateService
  • Replace repeated search scopes with a Searchable concern and shared partials
  • Extract complex billing queries into Billing::OverdueQuery to reduce N+1s
  • Introduce a RegistrationForm to coordinate user + company creation in a transaction
  • Move view helpers into OrderDecorator to simplify models and templates

FAQ

Refactoring aims to preserve behavior. I run and extend tests throughout and only propose migrations when adding indexes or columns that improve correctness or performance; those are documented separately.

How do you handle legacy code with poor or no tests?

I start by adding characterization tests for current behavior, then perform small refactors with tests guarding changes. This reduces risk and documents intent as I refactor.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational
refactor-rails skill by snakeo/claude-debug-and-refactor-skills-plugin | VeilStrat