module

Ralph::Validations

Macros

validate(attribute, message, &block)

Declare a validation with a block

Source
validates_exclusion_of(attribute, forbid, message = nil)

Exclusion validation - ensures attribute is NOT in forbidden values

validates_exclusion_of :username, forbid: ["admin", "root"]
validates_exclusion_of :email, forbid: ["blocked@example.com"], message: "is not allowed"
Source
validates_format_of(attribute, pattern, message = nil)

Format validation - ensures attribute matches regex pattern

validates_format_of :email, pattern: /@/
validates_format_of :username, pattern: /^[a-zA-Z0-9_]+$/, message: "contains invalid characters"
Source
validates_inclusion_of(attribute, allow, message = nil)

Inclusion validation - ensures attribute is in allowed values

validates_inclusion_of :status, allow: ["draft", "published", "archived"]
validates_inclusion_of :role, allow: ["user", "admin"], message: "is not a valid role"
Source
validates_length_of(attribute, min = nil, max = nil, minimum = nil, maximum = nil, range = nil, message = nil)

Length validation - ensures attribute length is within range

validates_length_of :name, min: 3, max: 50
validates_length_of :password, minimum: 8, message: "is too short"
validates_length_of :username, range: 3..20
Source
validates_numericality_of(attribute, message = nil)

Numericality validation - ensures attribute is numeric

validates_numericality_of :age
validates_numericality_of :price, message: "must be a number"
Source
validates_presence_of(attribute, message = nil)

Presence validation - ensures attribute is not nil/blank

validates_presence_of :name
validates_presence_of :email, message: "is required"
Source
validates_uniqueness_of(attribute, message = nil)

Uniqueness validation - ensures attribute is unique in the database

validates_uniqueness_of :email
validates_uniqueness_of :username, message: "is already taken"
Source

Nested types