Rails 行项目帮助
我正在尝试找出购买自行车零件的购物车的最佳方法。我遇到的问题是,我不能将所有组件添加到同一模型中,因为它们各自具有不同的规格(即链环具有“number_of_teeth”列,而前叉具有“crown_diameter”列) 。
现在我有每个组件的表,但这使得查找该项目的信息变得困难,因为我需要在控制器中列出每个组件,这似乎是多余的。我是否最好只制作一个组件模型并拥有一个“类型”列,然后添加一个“规格”列,该列将连接到另一个表,例如 chainring_specs,它将包含所有这些信息?
我想以尽可能最好的方式进行设置。谢谢。
i'm trying to figure out the best way to do shopping cart for bicycle components. the problem that i'm encountering is that i can't just add all the components to the same model because they each have different specs (i.e. a chainring has a column for "number_of_teeth" while a fork has a column for "crown_diameter").
right now i have a table for each component but that makes it difficult to look up information for that item in that i need to have each component listed in the controller which seems redundant. am i better off just making a components model and having a "type" column then adding a "specs" column that will connect to another table, say chainring_specs, that will have all of that information?
i want to get this set up the best way possible. thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,在我看来,创建更通用的组件模型将为您的 Web 应用程序提供更大的灵活性。我假设您将拥有一个为该购物车提供数据的数据库。
您的模型将由您使用的后端架构类型决定。可以支持所有组件的单表架构将允许您在一个地方处理 SKU、定价等。根据您面临的复杂性类型,您可能希望将描述和规格放在单独的表中。
希望这有帮助!
Yes, in my opinion, creating a more generic components model will give your web app a lot more flexibility. I'm assuming that you'll have a database feeding this shopping cart.
Your model(s) will be shaped by the type of back-end schema that you use. A one table schema that can support all of your components will allow you to handle skus, pricing, etc. in one place. Depending on the type of complexity that you face, you might want to have the description and specs in separate tables.
Hope this helps!