Skip to content

Instantly share code, notes, and snippets.

@ldenman
Created October 6, 2009 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ldenman/203225 to your computer and use it in GitHub Desktop.
Save ldenman/203225 to your computer and use it in GitHub Desktop.
Common Validations
# app/models/student.rb
class Student < ActiveRecord::Base
include CommonValidations::StudentTeacherValidations
end
# app/models/teacher.rb
class Teacher < ActiveRecord::Base
include CommonValidations::StudentTeacherValidations
end
# lib/common_validations/student_teacher_validations.rb
module CommonValidations
module StudentTeacherValidations
def self.included(klass)
klass.validate :foo
end
def foo
class_name = self.class.class_name
errors.add("name", "must be the class name: #{class_name}") unless name == class_name
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment