Implementing a lookup table in Rails

我只是一个虾纸丫 提交于 2019-12-04 07:36:21

I encountered the same problem as you, and solved it by creating a gem that adds a dynamic lookup table transparently into the model. I've blogged about it here: http://www.codelord.net/2011/08/09/guest-post-lookup-tables-with-ruby-on-rails/

And the code is here: https://github.com/Nimster/RailsLookup

If you're looking for a light-weight way to model enumerations/configuration without creating a separate table, definitely check out ActiveHash:

https://github.com/zilkey/active_hash

Do you really need it to be in the database?

If it is just a short list, a static array (loaded from a CSV file) might be enough.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!