Skip to content

Instantly share code, notes, and snippets.

@robjacoby
Created May 21, 2014 06:51
Show Gist options
  • Save robjacoby/82a9d3bfc4b802c7a919 to your computer and use it in GitHub Desktop.
Save robjacoby/82a9d3bfc4b802c7a919 to your computer and use it in GitHub Desktop.
validatable module
module Validatable
extend ActiveSupport::Concern
# Required dependency for ActiveModel::Errors
extend ActiveModel::Naming
def validate!
raise NotImplementedError, 'You need to implement this in the parent class'
end
def errors
@errors ||= ActiveModel::Errors.new(self)
end
# The following methods are needed to be minimally implemented
def read_attribute_for_validation(attr)
send(attr)
end
ClassMethods do
def human_attribute_name(attr, options = {})
attr
end
def lookup_ancestors
[self]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment