Displaying 2 results from an estimated 2 matches for "type_attr".
2007 Jul 06
2
validations of "type" when using Single Table Inheritance
...le Table Inheritance Rails doesn''t really 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...
2006 Mar 17
6
Updated the xml code to be more object-oriented
I changed the code to be more prototype-esque, and created a class
called XMLDoc. I may add more functionality to it later, hence the more
generic name, but you do something like this to convert XML to a hash:
XMLDoc = Class.create();
Object.extend(XMLDoc.prototype, {
initialize: function (xmlDoc) {
this.element = xmlDoc;
},
asHash: function () {
if (! this._xmlHash) {