validations

Why do my Datamapper Validation contexts disappear when I call them?

Given: class Foo include DataMapper::Resource property :title, String, :length => 255 validates_length :title, :in => (50..255), :allow_nil => false, :when => :long_title validates_length :title, :in => (5..50), :allow_nil => false, :when => :short_title end When I run: my_foo.valid? :long_title I get: Argume...

custom validation, included in a module, will not load

I am trying to include a custom validation across many models through a module, and I'm seeing some strange behavior. I wrote a custom validation called validates_as_unique which checks to see if a group of attributes is unique among records in the database. In a module called FactBehaviors I have: module FactBehaviors def self.includ...

mongoid uniqueness validation many-to-many relation

I have following association class Employee include Mongoid::Document employee_id :name references_many :companies, stored_as => :array, :inverse_of => :employees end class Company include Mongoid::Document field :name references_many :employees, stored_as => :array, :inverse_of => :companies end Now How can I check the uni...

Apply validation to single object only - Rails 3

Lets say I've Comment class that is polymorphic and I use it in many places within a system. class Comment < ActiveRecord::Base belongs_to :commentable, :polymorphic => true attr_accessible :content end And there is this one place in which I would like to apply validation on Comment's content length. How should I approach this prob...