Created
June 13, 2014 04:09
-
-
Save rocodev-tech/0ab0c02f536810a20fab to your computer and use it in GitHub Desktop.
app/models/order.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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