Hello, I have two models on the Rails app that I am working on, Article and Profile. I want them to have separate sets of categories. Should I create two different category models? article_category and profile_category? There will be lots of redundant code if I do this.
The question is, would both categories function the same way?
If they do, then I would use one model of categories, even though different names would be attributed different.
The trick is to DRY
or "Don't Repeat Yourself". So if anything gets written twice, you can absolutely refactor that into a smaller code.
If the models will be identical, then you should use a polymorphic relationship. See my response here: http://stackoverflow.com/questions/3498081/3499050#3499050
If the different category models will need additional logic, then I would use single table inheritance for this. You would have a parent Category class, and ArticleCategory and ProfileCategory would inherit from this. Basically all you will need to do is add a type field to categories and the two additional classes. This will eliminate redundant code and allow you to separate any model specific code into the appropriate class. Let me know if you need additional direction on this.