Exception: ActiveModel::ValidationError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/active_model/validations.rb

Overview

Active Model ValidationError

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ ValidationError

Returns a new instance of ValidationError.



463
464
465
466
467
# File '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

#modelObject (readonly)

Returns the value of attribute model.



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

def model
  @model
end