Rails STI: SuperClass Model Methods called from SubClass
- by Karl
I would like a little confirmation that I'm doing this correctly. Using rails single table inheritance I have the following models and class method:
class PhoneNumber < ActiveRecord::Base
def self.qual?(number)
klass = self
klass.exists?(:phone_number => phone_number)
end
end
class Bubba < PhoneNumber
end
class Rufus < PhoneNumber
end
Bubba.qual?("8005551212")
Tests pass and everything seems to work properly in rails console. Just wanted to confirm that I'm not headed for future trouble by using self in the superclass PhoneNumber and using that to execute class methods on subclasses from the parent.
Is there a better way?