Files
growstuff/app/models/order_item.rb
2013-05-22 11:22:10 +10:00

18 lines
475 B
Ruby

class OrderItem < ActiveRecord::Base
attr_accessible :order_id, :price, :product_id, :quantity
belongs_to :order
belongs_to :product
validate :price_must_be_greater_than_minimum
validates_uniqueness_of :order_id, :message => "may only have one item."
def price_must_be_greater_than_minimum
@product = Product.find(product_id)
if price < @product.min_price
errors.add(:price, "must be greater than the product's minimum value")
end
end
end