Why Use Rails Validations?
Given the power that check constraints give us, why would we bother with Rails validations at all? The answer is part of why taking a full-stack view of development is so important—the user experience.
Rails validations are an elegant and powerful way to give users a great experience when providing data via web forms. The validations API is incredibly expressive, configurable, and extensible. If you remove the validations from our code and attempt to register with an invalid email, you’ll get an exception—not a good user experience.
This does result in some duplication, which is a chance for inconsistency to creep into our app, but we can fight this by writing tests for each part of the stack (which we’ll do in ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access