W3cubDocs

/Ruby on Rails 5.1

class ActiveModel::ValidationError

Parent:
StandardError

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

Attributes

model[R]

Public Class Methods

new(model) Show source
Calls superclass method
# File activemodel/lib/active_model/validations.rb, line 427
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

© 2004–2017 David Heinemeier Hansson
Licensed under the MIT License.