Exception: ActiveModelPersistence::ObjectNotValidError

Inherits:
ModelError
  • Object
show all
Defined in:
lib/active_model_persistence.rb

Overview

Raised when trying to save an invalid object

Instance Method Summary collapse

Constructor Details

#initialize(invalid_object) ⇒ ObjectNotValidError

Create a new ObjectNotValidError constructing a message from the invalid object

Examples:

class Person
  include ActiveModelPersistence::Persistence
  attribute :id, :integer
  validates :id, presence: true
  attribute :name, :integer
  validates :name, presence: true
  attribute :age, :integer
  validates :age, numericality: { greater_than: 13, less_than: 125 }, allow_nil: true
end
begin
  Person.create!(id: 1)
rescue ObjectNotValidError => e
  puts e.message
end

Parameters:

  • invalid_object (Object)

    the invalid object being reported



44
45
46
# File 'lib/active_model_persistence.rb', line 44

def initialize(invalid_object)
  super(error_message(invalid_object))
end