rails-model

Enforce Rails model conventions with UUID uid, PaperTrail, and explicit association keys.

Updated Oct 12, 2024
One-click install
npx skills add https://github.com/samrocks03/shuttle-office-service --skill rails-model
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rails-model
Source: https://github.com/samrocks03/shuttle-office-service/tree/main/.claude/skills/rails-model
Command: npx skills add https://github.com/samrocks03/shuttle-office-service --skill rails-model

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill ensures every Rails model adheres to the project's conventions: using a UUID-based uid via the UidGenerator concern, documenting and enforcing has_paper_trail for audit trails, and applying explicit foreign and primary keys for all associations, as well as standardized enums, validations, scopes, and callbacks.

Core Features & Use Cases

  • UUID-based uid with UidGenerator and before_create
  • PaperTrail audit trails via has_paper_trail
  • Explicit associations with foreign_key and primary_key, including inverse_of
  • Enums, validations, scopes, and callbacks used consistently
  • Use Case: when creating a new model or refactoring an existing one to align with project conventions.

Quick Start

Apply these conventions whenever you create or modify a model under app/models to ensure a UUID-based uid, audit trails, and explicit association keys.

Frequently Asked Questions about rails-model

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

FAQPage Schema
How do I enforce UUID primary keys and audit trails in Rails ActiveRecord models?

You can enforce UUID primary keys and audit trails in Rails ActiveRecord models by applying a UUID-based uid through the UidGenerator concern and adding has_paper_trail for change tracking. This covers standardized identifiers and auditing across app/models.

What's the best way to standardize foreign_key and primary_key in Rails associations?

Standardizing foreign_key and primary_key in Rails associations requires explicitly defining both keys in every relation, including inverse_of. This eliminates ambiguity in ActiveRecord queries and maintains consistent relational metadata across models.

How does has_paper_trail work with UUID-based Rails models?

Has_paper_trail works with UUID-based Rails models by recording version history of changes to the model. The model uses a UUID-based uid generated by UidGenerator as its identifier, while PaperTrail separately tracks attribute modifications for auditing.

Do I need to specify foreign_key and primary_key for every Rails association?

You need to specify foreign_key and primary_key for every Rails association to maintain standardized metadata. Explicitly defining these keys, alongside inverse_of, prevents ActiveRecord from guessing and ensures relations correctly map to UUID-based identifiers.

Can I apply consistent enums, validations, and scopes when refactoring existing Rails models?

You can apply consistent enums, validations, and scopes when refactoring existing Rails models to align with project conventions. The process ensures associations, callbacks, and explicit keys are updated alongside UUID and audit trail enforcement.