rails-generators

Create Rails generators with templates, migrations, tests, and documentation.

12|2|Updated Mar 11, 2025
One-click install
npx skills add https://github.com/el-feo/ai-context --skill rails-generators
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rails-generators
Source: https://github.com/el-feo/ai-context/tree/main/skills/rails-generators
Command: npx skills add https://github.com/el-feo/ai-context --skill rails-generators

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps build production-ready Rails generators to automate models, services, controllers, and full-stack features, enforcing architectural patterns and reducing boilerplate.

Core Features & Use Cases

  • Generator scaffolding for models, services, controllers, and API patterns.
  • Templates, tests, and documentation generation integrated with Thor.
  • Support for namespacing, dependencies, and test framework hooks.

Quick Start

Define a new generator, create templates, and wire tests to generate consistent project code.

Frequently Asked Questions about rails-generators

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

FAQPage Schema
How do I create a Rails generator to automate model and controller scaffolding?

Rails generators use Thor to define custom scaffolding logic. Create a generator class inheriting from Rails::Generators::Base, set source_root to your templates directory, define public methods to render ERB templates, and invoke the generator with `rails generate your_generator_name`. This automates boilerplate for models, controllers, migrations, and tests.

Can I customize Rails generators with templates and options?

Yes. Define options using `class_option` to accept runtime parameters, create ERB templates in your templates folder, and use `template` and `create_file` methods to render them. This lets you generate namespaced features, API patterns, and full-stack code that follows your architectural standards.

What's the best way to integrate test framework hooks into a Rails generator?

Generators support hook-based composition for test frameworks. Define conditional template rendering based on test framework detection, invoke generator hooks at key points, and provide framework-specific templates. This ensures generated code includes appropriate test setup for your chosen testing tool.

Do Rails generators work with Rails 8 patterns and service object generation?

Production-ready generators support Rails 8 conventions and can generate services, models, controllers, and API endpoints. Define generator methods to scaffold services with proper namespacing, create corresponding templates for business logic, and ensure migrations and tests are generated alongside.

How do I organize namespaced generators for complex feature scaffolding?

Organize generators in lib/generators using namespace directories that match your feature structure. Define source_root per generator, use nested class names to create hierarchical generator commands, and support option flags for customization. This enables consistent, composable feature generation across your Rails project.

Can generators create multiple interdependent files like models, migrations, and documentation together?

Yes. Generators execute multiple public methods in sequence to create models, migrations, tests, and documentation files from templates. Use `invoke` to call other generators, chain `template` calls, and conditionally create files based on options, producing complete feature scaffolding in one command.