title: Using validates_with with ruby and mongoid
body: <p>I'm new to ruby and mongoid. I need to use validates_with and below is the code I have</p>
  
  <pre><code>class ValidatorClass &lt; ActiveModel::Validator
  
    def validate(record)
  
      if record.name == ""
  
          record.errors.add(:name, "An error occurred")
  
      end
  
    end
  end
  
  class Person
    include Mongoid::Document
    include Mongoid::Timestamps::Created
    include Mongoid::Timestamps::Updated
    include Mongoid::Versioning
    include ActiveModel::Validations
  
    field :id, type: Integer
    field :name, type: String
    field :age, type: Integer
  
     validates_with ValidatorClass, :on =&gt; :create
  
  end
  </code></pre>
  
  <p>But when I create the model with following code:</p>
  
  <pre><code>Person.create(id: 5, name: "", age: 50)
  </code></pre>
  
  <p>I don't get the error thrown. I'm not using Rails. I'm using just ruby with mongodb. Could anybody out there help me? Thanks in advance.</p>