views:

31

answers:

2

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

+1  A: 

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

Jimmy
I've already setup my DB that way, the thing is in web form, how do I save it?, I want the possibility to keep adding, removing, editing products in a form (with some javascript) and save it all to the database once the see its ok.Thanks
JaSk
+2  A: 

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

egarcia
thanks, let me check it out for a vote :-P ... perfect, just what I was looking for.Thanks
JaSk