Skip to content

Instantly share code, notes, and snippets.

@WaKeMaTTa
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WaKeMaTTa/10111451 to your computer and use it in GitHub Desktop.
Save WaKeMaTTa/10111451 to your computer and use it in GitHub Desktop.
class LineItem < ActiveRecord::Base
belongs_to :order
belongs_to :product
validates :product_id, :quantity, presence: true
validates :quantity, numericality: { only_integer: true }
before_save :set_price_to_products
private
def set_price_to_products
self.price = self.product.price
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment