Set value in controller using nested resource

Posted by vectran on Stack Overflow See other posts from Stack Overflow or by vectran
Published on 2010-04-12T01:51:10Z Indexed on 2010/04/12 1:53 UTC
Read the original article Hit count: 308

I have two models, product and order.

Product
 - cost
 - id

Order
 - cost
 - product_id

Each time someone places an order, it captures the product_id through a radio button value in the "new order" form.

In the controller when creating the new order it needs to set order.cost to order.product.cost. Logically I thought the code should be something like this:

def create
...
   @order.cost == @order.product.cost
...
end

However I can't seem to make it work at all, hence me asking the question here.

Any help is answering (or naming) the question would be greatly appreciated.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby