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 ...

Get Rails, Angular, Postgres, and Bootstrap now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.