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...
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...
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...
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...