Skip to content

Instantly share code, notes, and snippets.

@rurabe
Created July 25, 2012 18:57
Show Gist options
  • Save rurabe/3177892 to your computer and use it in GitHub Desktop.
Save rurabe/3177892 to your computer and use it in GitHub Desktop.
#DBC AcitveRecord Validation Practice
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