models

Design Rails 8 ActiveRecord models with associations, validations, scopes, and query objects.

Updated Mar 3, 2026
One-click install
npx skills add https://github.com/pelletencate/iron-horse --skill models-pelletencate
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: models
Source: https://github.com/pelletencate/iron-horse/tree/main/skills/models
Command: npx skills add https://github.com/pelletencate/iron-horse --skill models-pelletencate

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Rails projects often struggle to keep model logic organized as apps grow. This skill guides you through structuring ActiveRecord models with clear associations, validations, callbacks, scopes, concerns, and query objects to stay maintainable.

Core Features & Use Cases

  • Designing database models and associations
  • Writing validations and callbacks
  • Creating scopes and query methods
  • Extracting complex queries to query objects
  • Building form objects for multi-model operations
  • Organizing shared behavior with concerns
  • Creating custom validators
  • Preventing N+1 queries
  • Handling polymorphic associations and migrations with proper indexing

Quick Start

Define your ActiveRecord model with associations, validations, and scopes, then extract complex queries into a query object and use form objects for multi-model operations

Frequently Asked Questions about models

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

FAQPage Schema
How do I structure Rails models to avoid N+1 queries and complex logic?

To structure Rails models and avoid N+1 queries, define clear associations and extract complex logic into query objects, scopes, and concerns. This keeps ActiveRecord models organized, testable, and performant by enforcing indexing and preventing default scopes.

When should I extract ActiveRecord queries into query objects?

Extract ActiveRecord queries into query objects when complex filtering or multi-condition logic overwhelms standard scopes. Query objects encapsulate advanced retrieval logic, keeping your Rails models maintainable and preventing bloated scopes or N+1 query issues.

What is the best way to handle multi-model operations in Rails?

The best way to handle multi-model operations in Rails is by building form objects. Form objects coordinate validations and persistence across multiple ActiveRecord models, keeping logic organized and testable without bloating your core database models.

How do I organize shared behavior across Rails 8 models without callbacks?

Organize shared behavior across Rails 8 models by extracting it into concerns and custom validators. This approach isolates reusable logic and validations cleanly, keeping your ActiveRecord models maintainable and testable without relying on complex callbacks.

Does this approach support polymorphic associations and database indexing?

Yes, this approach supports polymorphic associations and database indexing. It enforces migrations and indexing best practices for ActiveRecord models, ensuring proper performance and data integrity when handling polymorphic relationships in Rails 8.