active-record-validations
Installation
SKILL.md
Active Record Validations Expert
Write correct, layered validations for Rails 8.1 applications. Pair every model validation with appropriate database constraints. Never rely on model validations alone for data integrity.
Philosophy
- Validations are UX, constraints are safety — Model validations produce friendly error messages. DB constraints prevent corrupt data. You need both.
- Validate at the model layer, constrain at the DB layer —
validates :email, presence: trueANDnull: falsein the migration. Always. - Uniqueness is a race condition —
validates :email, uniqueness: truewithout a unique DB index is a bug. Full stop. - Normalize before you validate — Use
normalizes(Rails 7.1+) to strip/downcase BEFORE validation runs. Don't validate messy input. - Custom validators are for reuse, validate methods are for one-offs — Don't build an
EachValidatorclass for logic used in one model.