Created
July 25, 2012 18:57
-
-
Save rurabe/3177892 to your computer and use it in GitHub Desktop.
#DBC AcitveRecord Validation Practice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Product < ActiveRecord::Base | |
attr_accessible :description, :imageurl, :price, :size, :title | |
validates_presence_of :title, :price, :description, :imageurl, :size | |
validates :title, :length => { :maximum => 50 }, :uniqueness => { :case_sensitive => false } | |
validates :description, :length => { :maximum => 250 } | |
validates :price, :format => { :with => /[\d\,]*\.\d{2}$/ } | |
validates :imageurl, :format => { :with => /#{URI::regexp}\.(jpg|png|gif)$/i } | |
validates :size, :inclusion => { :in => %w(small medium large) } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment