Dea*_*ean 9 activerecord ruby-on-rails ruby-on-rails-3.2
我正在设计一个管理许多不同设备租赁的应用程序.我想知道什么是为应用程序设计模型的最佳方法.我的软件必须管理许多不同类型的设备(包括数据类型),例如:
Speaker
Make - String
Model - String
Wattage - Integer
Price - Decimal
Light
Make - String
Model - String
Wattage - Integer
Price - Decimal
Microphone
Make - String
Model - String
Use - Choice of: Instrumental, Vocal, Versatile
Price - Decimal
Cable
Length - Decimal
Connector 1 - String
Connector 2 - String
Price - Decimal
Stand
Type - Choice of: Microphone, Speaker
Height - Decimal
Boom - Boolean
Price - Decimal
Run Code Online (Sandbox Code Playgroud)
我考虑过设计的方式:
但是铁路处理这些不同类型产品的最佳方式是什么?
动态属性 gem 应该允许您自动执行此操作:
https://github.com/moiristo/dynamic_attributes
可能有更好的宝石可以满足您的需求,但这是我发现的第一个。
如果您使用 Postgres 作为数据库,那么您可以使用hstore。有一些宝石可以与 hstore 一起使用。如果您负担得起,请订阅 Railscast 并观看有关实施 hstore 的截屏视频。
Activerecord-postgres-hstore似乎是解决这个问题的最佳选择。
| 归档时间: |
|
| 查看次数: |
1979 次 |
| 最近记录: |