Performance: Why validations protect data integrity
MEDIUM IMPACT
Validations affect server response time and database consistency by preventing invalid data from being saved.
class User < ApplicationRecord validates :email, presence: true, format: { with: URI::MailTo::EMAIL_REGEXP } validates :age, numericality: { greater_than_or_equal_to: 0 } end User.create(email: "", age: -5) # fails validation, no save
class User < ApplicationRecord # No validations end # Controller saves without checks User.create(email: "", age: -5)
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No validations | 0 | 0 | 0 | [X] Bad |
| Model validations before save | 0 | 0 | 0 | [OK] Good |