Posted By

Feb30th1712 on 10/25/08


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

webstic


product.rb


 / Published in: Rails
 

URL: http://www.google.com/notebook/public/14791221385681490756/BDRKWDAoQrZnEq9Ej#SDQ8rDAoQvNDfl88j

  1. class Product < ActiveRecord::Base
  2. validates_presence_of :title, :description, :image_url
  3. validates_numericality_of :price
  4. validates_uniqueness_of :title
  5. validates_format_of :image_url,
  6. :with => %r{\.(gif|jpg|png)$}i,
  7. :message => "must be a URL for a GIF, JPG, or PNG image"
  8. protected
  9. def validate
  10. errors.add(:price, "should be at least 0.01") if price.nil? || price < 0.01
  11. end
  12. end

Report this snippet  

You need to login to post a comment.