Hi all. I'm looking for suggestions of how other people have implemented a situation like the following. I'd like to create a base activerecord model, let's call it Widget, from which other classes are based. I'd like to store the name of the final class in the database and either use that information to load the proper class or to include a module that overrides certain methods of the base class. For example:
Widget < AR: Base RSSWidget < Widget HTMLWidget < Widget
w = Widget.first
Currently w is a generic widget; it doesn't know if it's really a RSSWidget or an HTMLWidget. Really, what I'm more interest in is if something, say Page, has many widgets, then I can iterate through all widgets for an instance of page and each will cast itself to the appropriate subclass (or include the proper module).
Is there an AR hook that I can use immediately after the model is loaded from the database to include the necessary module and either deserialize any additional information or load additional properties from other tables? I've read that AR has an abstract_class property, but it almost looks like it sees this problem from the other direction, with the tables belonging to the inherited classes, but maybe I've misunderstood it.
Any suggestions of how this may be done would be greatly appreciated.
Thanks, -Jeff