7 lines
224 B
Ruby
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
|