Validating Enum Presence
Enums are stored as integers in the database, but they can still have NULL
values unless explicitly validated. To prevent this, add presence
validation:
class User < ApplicationRecord
enum :status, { active: 0, inactive: 1, suspended: 2 }
validates :status, presence: true
end
This ensures that a user record cannot be saved without a valid status
.