class ActiveModelPersistence::ObjectNotValidError
Raised when trying to save an invalid object @api public
Public Class Methods
new(invalid_object)
click to toggle source
Create a new ObjectNotValidError
constructing a message from the invalid object
@example
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
@param invalid_object [Object] the invalid object being reported
Calls superclass method
# File lib/active_model_persistence.rb, line 44 def initialize(invalid_object) super(error_message(invalid_object)) end
Private Instance Methods
error_message(invalid_object)
click to toggle source
Create the exception message @return [String] the exception message @api private
# File lib/active_model_persistence.rb, line 53 def error_message(invalid_object) <<~ERROR_MESSAGE #{invalid_object.class} object is not valid Errors: #{invalid_object.errors.full_messages.pretty_inspect} Attributes: #{invalid_object.attributes.pretty_inspect} ERROR_MESSAGE end