# Include this in your classes to get ActiveRecord::Errors functionality. module Errorable # Setting errors on attributes will call ActiveRecord::Base.human_attribute_name, # so we need to mimic that method on the class that's including this module. def self.included(base) base.class_eval <<-END def self.human_attribute_name(attribute_key_name) attribute_key_name.humanize end END end def errors @errors ||= ActiveRecord::Errors.new(self) end def valid? errors.length == 0 end end