- Home
- Skills
- Thibautbaissac
- Rails Ai Agents
- Rails Model Generator
rails-model-generator_skill
269
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 thibautbaissac/rails_ai_agents --skill rails-model-generator- SKILL.md6.9 KB
Overview
This skill creates Rails models using a strict TDD workflow: write the spec first, create factories, generate migrations, implement the model, then refactor. It ensures models are delivered with tests, proper database schemas, validations, associations, scopes, and common patterns like enums and callbacks. The flow reduces regressions and keeps behavior specification central to development.
How this skill works
You define model requirements (attributes, associations, validations) then generate an RSpec model spec and a FactoryBot factory. Run specs to see failing tests, generate and run the migration, add the model file, then implement validations, associations, enums, scopes, and instance methods until specs pass. The skill includes templates and a checklist to enforce RED → GREEN → REFACTOR discipline.
When to use it
- Creating a new Rails model and corresponding DB table
- Adding or changing model validations or associations
- Defining enums, scopes, or instance methods with test coverage
- Setting up factories for model-driven tests
- Enforcing test-first discipline on Rails 8.1 development
Best practices
- Write a clear requirements template before coding: attributes, associations, validations, scopes, callbacks
- Create model spec and factory first, run tests to observe RED state
- Include null constraints, defaults, and indexes in migrations
- Keep specs focused: associations, validations, scopes, and instance methods in separate examples
- Use FactoryBot traits for variants and after(:create) for dependent records
- Run migrations and specs iteratively until tests are GREEN, then refactor
Example use cases
- Add a User model with name, email, status enum, and organization association following TDD
- Introduce validations and unique indexes for an existing model while keeping tests as the source of truth
- Create polymorphic associations or counter caches with accompanying specs and migrations
- Implement soft-delete behavior with scopes and instance methods covered by tests
- Generate a resource (model + factory + spec + migration) for a feature branch to ensure safe merges
FAQ
List table name, attributes with types and constraints, associations, validations, scopes, instance methods, and callbacks. This drives both spec and migration generation.
When do I add indexes and null constraints?
Add indexes and null constraints when generating or editing the migration, before running migrations. Tests should fail first (no table), then you migrate and continue implementing model behavior.