I want to create a model to store comments related to articles. I have a strong feeling that in the future I will want comments on other objects in the app too. How do I design commenting in my app so that it will be forward compatible with adding new parent objects. I want to avoid a scenario where have multiple controllers/models for each object to comment relationship.
After watching Ryan Bates screen cast on Nested Resource I have a firm grasp on how tp nest a resource under a single parent. How do I achieve this under 2 or more parent resources?
Thanks!
For “forward compatible with adding new parent objects” part of the question:
You could use Polymorphic Associations. Here’s a nice example. Also see RailsCast #154.
An example of how it could look like for you:
The
commentstable columns’ could be like this:Some Sample records: