Created
July 18, 2011 15:59
-
-
Save szymon-przybyl/1089943 to your computer and use it in GitHub Desktop.
order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Order < ActiveRecord::Base | |
belongs_to :product | |
belongs_to :user | |
validates_presence_of :user, :product, :product_quantity | |
validates_numericality_of :product_quantity, | |
:only_integer => true, :greater_than => 0, :less_than_or_equal_to => 10000, :allow_blank => true | |
validate :enough_product_quantity, | |
# if does not work | |
:if => lambda { |o| (!o.product_quantity.nil?) & (!o.product.nil?) & (!o.product.quantity_left.nil?) } | |
def enough_product_quantity | |
if product_quantity > product.quantity_left | |
errors.add(:product_quantity, :not_enough_quantity_of_product) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment