Skip to content
JezC edited this page Sep 13, 2010 · 3 revisions

Given a Parent class, define two single-table-inheritance models, “Daughter” and “Son”. Now create a selection box in the “New” or “Edit”, using the “subclasses_of” and you don’t see the Son and Daughter models. If I use them, explicitly, then I can see them. But what’s the point of only being to see the type I’ve already called? I want to find out what the types available are.

This seems like a chicken and egg problem. If I know what the types are, then I might as well just populate the selection list – but that’s not DRY, not extensible…

What’s the right way to do this, or is this an “unexpected behaviour” in subclasses_of?

If you run the app (“script/server”), then navigate to “http://localhost:300/parents” you should see two attempts to get the STI types, the second one works.

Tested using:

ruby: 1.8.7 (2009-06-12 patchlevel 174) [x86_64-darwin10.0.0]
Rails: 2.3.5
OS: Darwin Kernel Version 10.2.0: Tue Nov 3 10:37:10 PST 2009; root:xnu-1486.2.11~1/RELEASE_I386 i386

Clone this wiki locally