How to set up fields_for to choose a subclass?

I have an STI model where UtilityProvider is the parent class, and
there’s a sub-class for each specific utility provider.

When the user goes to choose a UtilityProvider, I want to present a
pull-down list of UtilityProvider.subclasses (or, more likely, a
filtered version of that), and when the user hits [submit] to create the
appropriate subclass.

To add a little spice to the question, I have a Premise model, and
premise has_many :utility_providers
and I’m using nested routes to represent the relationship:

resources :premises do
resources :utility_providers
end

So at the point in my code where I invite the user to create a new
UtilityProvider, I do have a @premise, but I don’t have a
@utility_provider.

I think this requires a fields_for rather than a form_for construct with
a collection_select within it, but I’m really stumped on how to
structure the form. What’s the Rails-y way to do this?

TIA.

  • ff