Introspection of validates_presence_of

Hello all.

I don’t know how to get all symbols passed to method
validates_presence_of in model. I’ve trying to use following solution:

class News < ActiveRecord::Base
validates_presence_of :title, :text

def validates_presence_of(*attr_names)
@@obligatory_fields = attr_names
ActiveRecord::Base.validates_presence_of(*attr_names)
end

def obligatory_fields
@@obligatory_fields
end
end

But when object news was created i’ve got following error message:

uninitialized class variable @@obligatory_fields in News.

I don’t understand when object News call methods:
validates_presence_of, attr_accessible, attr_reader, etc.
Maybe someone know how to deal with this problem?


Serhiy Boiko, CRIS-UANIC

On 5/18/06, СеÑ?гей Ð?ойко [email protected] wrote:

end
end

Try:

class News < ActiveRecord::Base
def self.validates_presence_of(*attr_names)
@@obligatory_fields = attr_names
super(*attr_names)
end

validates_presence_of :title, :text
cattr_accessor :obligatory_fields
end