Forum: Ruby on Rails Single Table Inheritance

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
hugh (Guest)
on 2005-11-12 18:00
(Received via mailing list)

I'm trying to build out an app with a couple of tables (people,
contacts) using single table inheritance. The people table has the
type field and is for, clients, employees, managers etc. contacts
simply holds phone numbers and email numbers. I scaffolded out person
and contact and have created the basic files below. For the life of
me can't create a related phone number or email.

in people_controller.rb I have (model below):

  def create_phone
      person = Person.find(params[:id])
      redirect_to :action => 'edit', :controller => 'Phones', :id =>

with the idea this can be called from clients or employees.

and I get undefined method `Phone' for Person:Class

Also if the scaffolded CRUD methods exist in person will they not be
inherited by client? To get anything to work I had to scaffold client
out as well.

  class Person < ActiveRecord::Base
    has_many :contacts

  class Client < Person

  class Contact < ActiveRecord::Base
    belongs_to :person

  class Phone < Contact

Thanks in advance for any help,
wemigh (Guest)
on 2005-11-12 18:05
(Received via mailing list)
Instead of Person.Phone.create, you should have:

When you capitalize, Ruby assumes that you're talking about the class
(Person and Phone) rather than an instance (person and phone).

-- Will

On Sat, 12 Nov 2005 10:57:39 -0500, Hugh Kelsey
This topic is locked and can not be replied to.