Skip to content

Commit

Permalink
自由課題, validates_length_of
Browse files Browse the repository at this point in the history
  • Loading branch information
kyanny committed Jan 19, 2010
1 parent de24ab8 commit ac46114
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions depot/app/models/product.rb
Expand Up @@ -5,6 +5,7 @@ class Product < ActiveRecord::Base
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 でなければなりません'
validates_length_of :title, :minimum => 10

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

0 comments on commit ac46114

Please sign in to comment.