开发者

Rails: model vs. array

开发者 https://www.devze.com 2023-02-03 06:20 出处:网络
When should an array of values become a full fledged model? My problem is开发者_JAVA百科 an application that is littered with models for such mundane objects as Country, Degree, Profession, etc. which

When should an array of values become a full fledged model? My problem is开发者_JAVA百科 an application that is littered with models for such mundane objects as Country, Degree, Profession, etc. which are all simply parts of a user registration form. Should these constant arrays just be hard-coded or is there another better way to store them than using ActiveRecord models?


If it makes sense to have them as database tables, then it makes sense to have them as models. And I would argue that it does make sense to have at least some of these as database tables, because that way you can give your client the ability to edit them on-the-fly. I don't want a programmer to be responsible for maintaining a list of countries or professions.

(In a recent application I worked on that had an international focus, the ability for the client to edit the list of countries was a key requirement; in many settings, what countries are listed and what they are named have controversial political implications, so the client needed domain experts to discuss and decide on country names.)


Hardcoded Array is fine, creating a model for this is part of the antipatterns listed in 'Rails Antipatterns' from Chad Pytel

0

精彩评论

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

关注公众号