Junior Track Roadmap

ActiveRecord validations (complex)

This course covers ActiveRecord validation options beyond a basic presence check, using this project's real models and a scratch table. It starts with the four shapes of the length option and moves to scoped, case-insensitive uniqueness. It then covers format with shared patterns, numericality, inclusion, exclusion and confirmation. Later lessons add conditional rules with if:, unless: and on: contexts. They also cover custom validate methods that call errors.add, and several ways to read the errors object. The last lesson combines every option on one Article model.

What you'll learn

  • ✓The minimum, maximum, in and is keys of the length option
  • ✓Uniqueness with scope:, case_sensitive: false and a custom message:
  • ✓format with shared patterns, and numericality limits including only_integer
  • ✓inclusion, exclusion and confirmation checks
  • ✓Conditional validations with if:, unless: and on: contexts
  • ✓Custom validate methods and reading errors with of_kind?, added?, details and each
Free preview · Lesson 1 3 min read

length: four shapes for one option

In ActiveRecord: model introduction, the lesson "Validations: a rule before saving" introduced validates as a rule Rails checks before it saves a record. It ended by saying the options, the ways a check can fail, and how to report failures to a user would get a course of their own. In ActiveRecord:…

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...