Topic: Using Single Table Inheritace with drop down lists
I'm having a little trouble working out how to classify which 'type' a record should be based on Single Table Inheritance.
Let's say I have a table Contacts which has some fields like Name, PhoneNumber, etc. but also has a drop down field that has values such as "Personal", "Professional", "Company", etc.
Now I have a model called Contact and it has some sub classes. The code looks like:
class Contact < ActiveRecord::Base
class ContactPersonal < Contact; end
class ContactProfessional < Contact; end
class ContactCompany < Contact; end
I'm essentially having two issues.
1. How do I get a list of these subclasses for automatically populating the drop down list?
2. Where is the best place to decide what type of object to create. Would a case statement in the controller, based off the selected drop down list item, be the best place, or is there a better way?