Redid up to end of Chapter 6 under Rails2.2.2 and Gems 1.3.1, with Product.date_available
[depot.git] / app / models / product.rb
1 class Product < ActiveRecord::Base
2 validates_presence_of :title, :description, :image_url
3 validates_numericality_of :price
4 validate :price_must_be_at_least_a_penny
5 validates_uniqueness_of :title
6 validates_format_of :image_url,
7 :with => %r{\.(gif|jpg|png)$}i,
8 :message => "must be a URL for GIF, JPG, or PNG image."
9
10 protected
11 def price_must_be_at_least_a_penny
12 errors.add(:price, 'should be at least 0.01') if price.nil? || price < 0.01
13 end
14 end