Skip to content

Instantly share code, notes, and snippets.

@elrok123
Created May 12, 2013 14:45
Show Gist options
  • Save elrok123/5563805 to your computer and use it in GitHub Desktop.
Save elrok123/5563805 to your computer and use it in GitHub Desktop.
Order class
class Order < ActiveRecord::Base
attr_accessible :client_id, :order_total
has_many :orderedproducts
has_many :products, through: :orderedproducts, :source => :product
has_one :client
before_save :generate_total
def generate_total
self.order_total = self.products.sum(:product_price)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment