Rails STI: SuperClass Model Methods called from SubClass
Posted
by Karl
on Stack Overflow
See other posts from Stack Overflow
or by Karl
Published on 2010-03-30T03:52:01Z
Indexed on
2010/03/30
3:53 UTC
Read the original article
Hit count: 365
ruby
|ruby-on-rails
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?
© Stack Overflow or respective owner