rails-concern

Generate Rails concerns with accompanying RSpec specs for models and controllers.

643|80|Updated Dec 9, 2025
One-click install
npx skills add https://github.com/ThibautBaissac/rails_ai_agents --skill rails-concern
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rails-concern
Source: https://github.com/ThibautBaissac/rails_ai_agents/tree/main/skills/rails-concern
Command: npx skills add https://github.com/ThibautBaissac/rails_ai_agents --skill rails-concern

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Creates Rails concerns to share behavior across models or controllers, reducing duplication and making future changes safer through a test-driven approach.

Core Features & Use Cases

  • Test-driven scaffolding: generates ActiveSupport::Concern modules with accompanying specs.
  • Model and controller support: handles concerns for both models and controllers, plus common shared logic.
  • Refactoring aid: helps extract duplicated validations, callbacks, scopes, or helpers into reusable modules.

Quick Start

Write a failing spec for the desired shared behavior, then run the generator to scaffold the concern and its specs.

Frequently Asked Questions about rails-concern

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I extract duplicated Rails model logic into a reusable module?

Extracting duplicated Rails model logic into a reusable module involves creating an ActiveSupport::Concern. This Skill scaffolds the concern alongside RSpec tests, ensuring shared validations, callbacks, or scopes are safely refactored without breaking existing functionality.

What is the best way to test shared Rails concerns with RSpec?

Testing shared Rails concerns with RSpec is best achieved through a tests-first workflow. By writing failing specs for the desired behavior before implementation, you ensure the extracted ActiveSupport::Concern module functions correctly when mixed into models or controllers.

Can I use Rails concerns to share behavior across both models and controllers?

Yes, you can use Rails concerns to share behavior across both models and controllers. The generator handles scaffolding for both ActiveSupport::Concern model modules and controller concerns, allowing you to extract duplicated helpers or logic into shared code.

How do I start refactoring a Rails app using a test-driven approach?

To start refactoring a Rails app using a test-driven approach, write a failing RSpec spec for the desired shared behavior first. Then, generate the concern module to scaffold the implementation, ensuring your refactoring safely extracts duplicated logic.

When should I avoid using ActiveSupport::Concern for modular design in Rails?

You should avoid using ActiveSupport::Concern for modular design when the duplicated logic is minimal or highly specific to a single class. Overusing concerns can obscure code flow, so reserve them for extracting genuinely shared validations, callbacks, or helpers across multiple models.