Skip to content

Instantly share code, notes, and snippets.

@rocodev-tech
Created June 13, 2014 04:09
Show Gist options
  • Select an option

  • Save rocodev-tech/0ab0c02f536810a20fab to your computer and use it in GitHub Desktop.

Select an option

Save rocodev-tech/0ab0c02f536810a20fab to your computer and use it in GitHub Desktop.
app/models/order.rb
class Order < ActiveRecord::Base
belongs_to :user
has_many :items, :class_name => "OrderItem", :dependent => :destroy
has_one :info, :class_name => "OrderInfo", :dependent => :destroy
accepts_nested_attributes_for :info
def build_item_cache_from_cart(cart)
cart.items.each do |cart_item|
item = items.build
item.product_name = cart_item.title
item.quantity = 1
item.price = cart_item.price
item.save
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment