123456789_123456789_123456789_123456789_123456789_

Exception: ActiveModel::ValidationError

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, StandardError
Instance Chain:
self, StandardError
Inherits: StandardError
  • ::Object
Defined in: activemodel/lib/active_model/validations.rb

Overview

Raised by validate! when the model is invalid. Use the #model method to retrieve the record which did not validate.

begin
  complex_operation_that_internally_calls_validate!
rescue ActiveModel::ValidationError => invalid
  puts invalid.model.errors
end

Class Method Summary

Instance Attribute Summary

Constructor Details

.new(model) ⇒ ValidationError

[ GitHub ]

  
# File 'activemodel/lib/active_model/validations.rb', line 463

def initialize(model)
  @model = model
  errors = @model.errors.full_messages.join(", ")
  super(I18n.t(:"#{@model.class.i18n_scope}.errors.messages.model_invalid", errors: errors, default: :"errors.messages.model_invalid"))
end

Instance Attribute Details

#model (readonly)

[ GitHub ]

  
# File 'activemodel/lib/active_model/validations.rb', line 461

attr_reader :model