From 01acb619b253647b8950dbb315c84bb4109bef06 Mon Sep 17 00:00:00 2001 From: Jenua Boiko Date: Mon, 24 Oct 2011 11:36:31 +0300 Subject: [PATCH] Add validations on product price and discount --- app/models/discount.rb | 2 +- app/models/product.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/discount.rb b/app/models/discount.rb index 589a0b7..4600be5 100644 --- a/app/models/discount.rb +++ b/app/models/discount.rb @@ -1,5 +1,5 @@ class Discount < ActiveRecord::Base has_many :users - validates :value , :presence => true + validates :value , :presence => true, :numericality => { :greater_than => 0, :less_than_or_equal_to => 1.0 } end diff --git a/app/models/product.rb b/app/models/product.rb index b964685..9e444cd 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -9,6 +9,7 @@ class Product < ActiveRecord::Base validates :title, :presence => true, :length => {:minimum => 3, :maximum => 300} validates :company_id,:group_id, :numericality => true, :presence => true validates :status, :presence => true, :inclusion => { :in => ["new", "enable", "disable"] } + validates :price, :presence => true, :numericality => { :greater_than => 0 } before_save :update_product_description