Kavin-Kannan

Rails Best Practices Skill

0
0
# Install this skill:
npx skills add Kavin-Kannan/rails-best-practices-skill

Or install specific skill: npx add-skill https://github.com/Kavin-Kannan/rails-best-practices-skill

# Description

A Claude Agent Skill providing comprehensive Rails best practices from rails-bestpractices.com

# SKILL.md

Rails Best Practices Skill

A comprehensive skill that helps Claude review, analyze, and generate Ruby on Rails code according to established best practices.

Purpose

This skill provides Claude with expert knowledge of Rails best practices sourced from rails-bestpractices.com. This skill is automatically invoked for both code review and code generation - when enabled, Claude will:

  • Review code against established Rails conventions
  • Generate code following Rails best practices
  • Identify Rails anti-patterns and suggest improvements
  • Flag security vulnerabilities and performance issues
  • Ensure code follows Rails community standards
  • Provide detailed code review feedback with specific recommendations
  • Apply best practices automatically when writing new Rails code

When to Use

This skill is automatically invoked and prioritized when Claude is:
- Reviewing Ruby on Rails code
- Generating or writing Ruby on Rails code
- Analyzing Rails code for best practices
- Performing code reviews on Rails applications
- Refactoring Rails applications
- Debugging Rails issues
- Explaining Rails concepts

Capabilities

Time and Timezone

  • Enforces use of Time.zone.now instead of Time.now
  • Recommends client-side time display instead of time_ago_in_words

ActiveRecord

  • Ensures save return values are checked or save! is used
  • Warns against default_scope usage
  • Recommends batched finders for large datasets
  • Identifies and fixes N+1 query problems

Controllers

  • Prevents modification of params hash
  • Recommends route restrictions
  • Enforces strong parameters usage

Error Handling

  • Ensures StandardError is rescued, not Exception
  • Recommends specific exception handling

Code Organization

  • Applies "Tell, don't ask" principle
  • Recommends namespaced models
  • Identifies empty helpers

Views

  • Recommends local variables in partials
  • Avoids instance variable dependencies

Migrations

  • Recommends say and say_with_time for logging

Security

  • Checks for SQL injection risks
  • Identifies XSS vulnerabilities
  • Ensures CSRF protection
  • Validates authentication/authorization

Code Quality

  • Enforces DRY principle
  • Ensures single responsibility
  • Removes trailing whitespace

Performance

  • Optimizes database queries
  • Recommends appropriate eager loading
  • Suggests caching strategies

Resources

This skill includes:
- Comprehensive best practices documentation organized by category
- Code examples for each practice
- Common anti-patterns to avoid
- Reference links to source material

Usage Examples

Code Review

When reviewing Rails code, Claude will:
- Comprehensively analyze code against Rails best practices
- Identify N+1 query problems and suggest optimizations
- Flag params hash modifications and security issues
- Suggest eager loading opportunities
- Recommend security improvements
- Check for proper error handling patterns
- Verify adherence to Rails conventions
- Provide actionable feedback with code examples

Code Generation

When generating Rails code, Claude will automatically:
- Follow Rails best practices from the start
- Use Time.zone.now instead of Time.now
- Check save return values or use save!
- Avoid default_scope anti-patterns
- Use strong parameters in controllers
- Prevent N+1 queries with proper eager loading
- Apply proper error handling patterns
- Follow Rails naming conventions and structure
- Implement security best practices

Refactoring

When refactoring, Claude will:
- Extract repeated code
- Apply "Tell, don't ask" principle
- Improve query performance
- Enhance code organization

Categories

The skill covers practices in:
- Timezone handling
- ActiveRecord patterns
- Controller design
- Error handling
- Code organization
- View patterns
- Migrations
- Security
- Code quality
- Performance optimization
- Testing
- General Rails conventions

Source and Attribution

This skill is based on concepts from rails-bestpractices.com,
a community-driven collection of Rails best practices.

Important: Content is rewritten in our own words, not copied verbatim. We provide
attribution and source links throughout. See COPYRIGHT.md for copyright
information and legal considerations.

Version

Current version: 1.0.0

Maintenance

This skill is maintained and updated as new Rails best practices emerge. Categories are organized for easy reference and extension.

Attribution

This skill is based on publicly available best practices from rails-bestpractices.com. The practices themselves are community knowledge. This skill structure, organization, and documentation are original work.

License

MIT License - See LICENSE file for details.

Contributing

See CONTRIBUTING.md for how to contribute improvements, new practices, or documentation updates.

# README.md

Rails Best Practices Skill

A Claude Agent Skill that provides comprehensive Rails best practices sourced from rails-bestpractices.com.

What is This?

This is a Claude Agent Skill - a specialized knowledge package that helps Claude review, analyze, and generate Ruby on Rails code following community best practices. This skill is automatically invoked for both code review and code generation when Claude is working with Ruby on Rails code.

Quick Start

Install for Claude Code

mkdir -p ~/.claude/skills
cp -r rails_best_practices ~/.claude/skills/rails-best-practices

See QUICK_START.md for 3-step installation.

Features

When enabled, Claude will automatically:
- ✅ Use Time.zone.now instead of Time.now
- ✅ Check save return values or use save!
- ✅ Avoid default_scope anti-patterns
- ✅ Prevent N+1 query problems
- ✅ Use strong parameters in controllers
- ✅ Follow Rails conventions
- ✅ Apply security best practices
- ✅ Optimize database queries
- ✅ And much more!

Installation

  • Claude Code: See INSTALL.md
  • Claude Apps: Enable in Settings → Skills
  • API: Include in Messages API requests

Sharing with Community

Want to share this skill with other developers?

See HOW_TO_SHARE.md for complete step-by-step instructions!

Quick version:
1. Create GitHub repository
2. Submit to Anthropic Skills Marketplace (when available)
3. Share with Rails community

Documentation

Structure

rails-best-practices/
├── SKILL.md              # Main skill description (required)
├── README.md             # This file
├── INDEX.md              # Practices index
├── LICENSE               # MIT License
├── timezone/             # Time/timezone practices
├── active_record/        # ActiveRecord practices
├── controllers/          # Controller practices
├── error_handling/       # Error handling practices
├── code_organization/    # Code organization practices
├── views/                # View practices
├── migrations/           # Migration practices
├── security/             # Security practices
├── code_quality/         # Code quality practices
├── performance/          # Performance practices
├── testing/              # Testing practices
└── general/              # General Rails conventions

Categories Covered

  • Timezone: Time handling best practices
  • ActiveRecord: Database and model patterns
  • Controllers: Controller design patterns
  • Error Handling: Exception handling
  • Code Organization: Structure and patterns
  • Views: View and partial patterns
  • Migrations: Database migration practices
  • Security: Security best practices
  • Code Quality: DRY, SOLID, clean code
  • Performance: Query optimization, caching
  • Testing: Test coverage and quality
  • General: Rails conventions and standards

Source and Attribution

All practices are based on concepts from rails-bestpractices.com,
a community-driven collection of Rails best practices created by Richard Huang and contributors.

Important: This skill does NOT copy verbatim text from rails-bestpractices.com. All content
is rewritten in our own words, organized for Claude Skill format, with proper attribution.
See COPYRIGHT.md for detailed copyright information.

Contributing

We welcome contributions! See CONTRIBUTING.md for:
- How to add new Rails practices
- Contribution guidelines (follows Claude's standards)
- AI usage disclosure requirements
- Pull request process
- Code of conduct

Important: All contributions must follow Claude's contribution guidelines, including disclosure of AI tool usage and human verification of all changes.

License

MIT License - See LICENSE file for details.

Version

Current version: 1.0.0

Support


Ready to share? → See HOW_TO_SHARE.md for complete instructions!

# Supported AI Coding Agents

This skill is compatible with the SKILL.md standard and works with all major AI coding agents:

Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.