开发者

Is a table with constant values in rails a good idea? or is a constant hash smarter?

I am creating an application where I need to categorize one of my models. There are five categories and they will not change, at least not for now. The object can only have one category at once. My two ideas are:

  1. Create a whole table for adding the categories and add them in the migration file. I would then store the category id in the db for my object. Read about this causing problems with testing so I'm not sure. And, it seems a bi开发者_StackOverflowt overkill.

  2. Add a constant hash in my model for hosting the categories. I would then store the int key in my object.

Is there any better way I have not thought about? Are there any plugins for creating enums in rails?

Thanks


I have used this plugin https://github.com/adzap/active_enum some time ago and I think it works OK. You should definitely try it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜