开发者

How do I save tabular data in rails?

开发者 https://www.devze.com 2023-01-04 12:16 出处:网络
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 rec

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 rec开发者_开发知识库ipe 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


This is explained masterfully on railscasts #196, #197 and #198. Give them a look.


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

0

精彩评论

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