tap/app/validators/in_stock_validator.rb
2015-01-15 00:39:34 +01:00

7 lines
224 B
Ruby

class InStockValidator < ActiveModel::Validator
def validate(record)
record.order_products.each do |op|
record.errors[op.product.name] = "is not in stock anymore" if op.count > op.product.stock
end
end
end