I have a simple cart system that I have been working on for a little while for an application and am needing a little help in trying to figure out how to update a particular attribute in a join table (Between Order and Products).
Here is the code:
def add_product_to_cart
@product = Product.by_client(current_client).first
@order = current_order
unless @order.products.exists? :id => @product.id
@order.products << @product
end
end
I am trying to update a particular attribute when I update the @order.products…
This is what I am trying to do:
@order.products << @product –> When this happens I need to update a :price attribute..
Anyway of doing this?
Just off the top of my head. Here’s the sum reference:
http://ar.rubyonrails.org/classes/ActiveRecord/Calculations/ClassMethods.html#M000296