module SimpleModel module Errors def errors @errors ||= ErrorsHash.new @errors end def valid? self.errors.clear if errors validate self.errors.blank? || self.errors.empty? end def errors? !self.errors.nil? && !errors.empty? end def errors_on(attr) self.valid? [self.errors.on(attr.to_s)].flatten.compact end alias :error_on :errors_on def errors_to_s error_string = "" self.errors.full_messages.each do |m| error_string << "#{m} " end error_string end def validate # Override to implement validation end def errors_for_flash error_string = "" errors.full_messages.each do |m| error_string << "