Skip to content

Commit

Permalink
Add validates
Browse files Browse the repository at this point in the history
  • Loading branch information
kyanny committed Jan 19, 2010
1 parent 44910d3 commit 2cc7deb
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions depot/app/models/product.rb
@@ -1,2 +1,12 @@
# -*- coding: utf-8 -*-
class Product < ActiveRecord::Base
validates_presence_of :title, :description, :image_url
validates_numericality_of :price
validate :price_must_be_at_least_a_cent
validates_uniqueness_of :title
validates_format_of :image_url, :with => %r{\.(gif|jpe?g|png)$}i, :message => 'は GIF, JPG, PNG 画像の URL でなければなりません'

def price_must_be_at_least_a_cent
errors.add(:price, "は最小でも 0.01 以上でなければなりません") if price.nil? || price < 0.01
end
end

0 comments on commit 2cc7deb

Please sign in to comment.