Skip to content

Instantly share code, notes, and snippets.

@jacquescrocker
Created March 31, 2010 02:35
Show Gist options
  • Save jacquescrocker/349865 to your computer and use it in GitHub Desktop.
Save jacquescrocker/349865 to your computer and use it in GitHub Desktop.
require "rubygems"
require "mongoid"
class Person
include Mongoid::Document
field :name
before_validate :check_for_name
def check_for_name
errors.add(:name, "NO NAME") if self.name.blank?
end
end
p = Person.new
p.save #=> false
p.errors #=> #<OrderedHash {:name=>["NO NAME"]}>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment