I'm writing and app to let the production people estimate costs for building some products, they want to be able to give the product's base data (name of the product, client, etc) plus make the recipe for it (which materials are needed in order to build it) in the same page, and I was wondering how do I save tabular data in my rails controller (ie. a products price, quantity, etc.) can It be done? Thanks
我写和应用让生产的人估计成本为构建一些产品,他们希望能够给产品的基本数据(产品名称、客户等)+使它的食谱(需要哪些材料来构建它)在同一页,我在想我该如何拯救我的rails控制器(即表格数据。产品价格、数量等)可以做吗?谢谢
2 个解决方案
#1
#2
1
You would need a model for each item, with relationships between them all
您需要为每个项目建立一个模型,并在它们之间建立关系
so a model for Product and Materials
一个产品和材料的模型。
#app/model/product.rb
has_many :materials
#app/model/material.rb
belongs_to :product
and for products you could have your table setup with name, client_name, etc. For materials you could have the table setup as name, quantity, unit_cost, product_id
对于产品,可以使用名称、client_name等设置表。对于材料,可以使用名称、数量、unit_cost、product_id等设置表
#1
2
This is explained masterfully on railscasts #196, #197 and #198. Give them a look.
这在第196节、第197节和第198节火车上得到了很好的解释。给他们看看。
#2
1
You would need a model for each item, with relationships between them all
您需要为每个项目建立一个模型,并在它们之间建立关系
so a model for Product and Materials
一个产品和材料的模型。
#app/model/product.rb
has_many :materials
#app/model/material.rb
belongs_to :product
and for products you could have your table setup with name, client_name, etc. For materials you could have the table setup as name, quantity, unit_cost, product_id
对于产品,可以使用名称、client_name等设置表。对于材料,可以使用名称、数量、unit_cost、product_id等设置表