Ralph::Validations::Errors
Stores validation errors for a model
Errors provides both backward-compatible string access and structured error access for i18n and detailed error handling.
Basic Usage
errors = Errors.new
errors.add("name", "can't be blank")
errors.add("email", :taken)
errors.add("password", :too_short, count: 8)
errors.full_messages # => ["name can't be blank", "email has already been taken", "password is too short (minimum is 8 characters)"]
errors.details # => {"name" => [{error: :blank}], "email" => [{error: :taken}], ...}
Constructors
new
SourceInstance methods
Get all error messages for an attribute (backward compatible - returns strings)
Add an error for a specific attribute (with explicit message and code)
Add an error for a specific attribute (string message - backward compatible)
Add an error for a specific attribute (structured with code)
details
Get error details for i18n/structured access
Returns a hash where each attribute maps to an array of error details. Each detail contains the error code and any options.
Example
errors.add("name", :blank)
errors.add("password", :too_short, count: 8)
errors.details
# => {
# "name" => [{error: :blank}],
# "password" => [{error: :too_short, count: 8}]
# }
Get all validation errors for an attribute (structured)
Check if a specific error code exists for an attribute