I’m creating a message-board website using Rails. I have a Topic class and Post class.
it is easy to notice the similarity between the two classes (content, title, user_id..)
what is the best practice in Rails with this scenario?
should Topic inherit from Post? how does it work?
Module Mixins: just include this module on any class
Inheritance (STI): you have to use the same table for those classes
Polymorphic: you have to use a different tables for each class
In my opinion, its really hard to answer in general what is the best practice, since it really depends on the situation–in some cases you may even want to use a combination, god forbid.
I would stick with Module Mixins because its simple and flexible. If you think you’ll be double writing queries a lot because you have two separate tables, then try Inheritance (STI). From experience, definitely Polymorphic can be a headache, with a ton of gotchas if your not familiar, so probably not worth it for 2 classes.
General Rails best practice? K eep I t S imple S tupid