ActiveModel::Errors
class ActiveModel::Errors
Active Model Errors
Provides a modified Hash
that you can include in your object for handling error messages and interacting with Action View helpers.
A minimal implementation could be:
class Person # Required dependency for ActiveModel::Errors extend ActiveModel::Naming def initialize @errors = ActiveModel::Errors.new(self) end attr_accessor :name attr_reader :errors def validate! errors.add(:name, :blank, message: "cannot be nil") if name.nil? end # The following