Views/Controllers for polymorphic association


I've just been revisiting this issue for a project. I'm a relative noob so my approach may not be the "correct" one. I've created a plugin called acts_as_polymorph that:

Proxies the attributes from the polymorph table into the attribute table Overwrites the new, save and update methods to synchronise updates to both tables in a transaction Implements find_poly_* methods via method_missing that scopes the finds and :includes the polymorph table

With this approach you can: 1. Treat all attributes of the polymorph table as if they are part of the attribute table(s) 2. Do normal new, create, save, updates and ensure tables are synchronised 3. Have extended finders that include the polymorph table automatically

For forms, this means you just treat the attributes from the polymorph table as if they are in the attribute table - no special handling requried.

My code isn't finished (no tests, not implemented destroy, ...) but its working well enough to suggest this might be a reasonable strategy. Happy to share the code as-is if you want, just email me.

Cheers --Kip