search for: validates_type

Displaying 1 result from an estimated 1 matches for "validates_type".

2007 Jul 06
2
validations of "type" when using Single Table Inheritance
...y validate the "type" field or provide some mechanism to do so? seems like a good way to corrupt a database. Because the "type" is also a special attribute, I had to resort to an ugly hack like: class ActiveRecord::Base def type_attr self[:type] end def self.validates_type(options={}) validates_inclusion_of :type_attr, options end end so that I could write: class Fruit < ActiveRecord::Base validates_type :allow_nil => true, :in => %w{ Apple } # could be dynamic subclass_of but make faster! (obviously th...