Update: After thinking about this some more I think this question includes both polymorphism and STI.
Let's say I have the following:
class Vehicle < ActiveRecord::Base
belongs_to :dealership
...
end
class Car < Vehicle
...
end
class Truck < Vehicle
...
end
The Car and Truck models have the same attributes but different logic in the model, so they all just use the Vehicles table.
I'd like to make a generic form that allows someone to create a new vehicle record, and to select whether it is a "Car" or "Truck". On the backend this form should then create a "Car" or "Truck" record, not a generic "Vehicle" record.
Question: How do you present this option in a Rails form? Specifically, are there methods for listing the child types of an abstract base model, and/or is there a simple way to present these as (for instance) a Select element in a form?
The reason I am looking to create a form that can make a car or a truck opposed to just having two different forms for cars and trucks, is eventually I'd also like these models to be nested in a parent, "Dealership." I'd like to be able to not only create new vehicles and select "car" or "truck" as an option, but to be able to have nested forms where a user could load a "Dealership" and view/edit all the cars and trucks that belong to that dealership in a single form. I know how to set that up using accepts_nested_attributes_for on a simple association like Vehicle belongs_to :dealership, but I'm not sure how to set it up for child models that inherit from Vehicle.