This file contains hidden or 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 Phone < ActiveRecord::Base | |
belongs_to :phonable, :polymorphic=>true | |
acts_as_audited | |
validates_presence_of :number | |
before_validation :parse_phone | |
def parse_phone | |
if self && self.number !=nil | |
number = self.number.gsub(/\D/,"") | |
if number.length == 10 |
This file contains hidden or 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 DateOfBirthValidator < ActiveModel::Validator | |
def validate(record) | |
record.errors[:date_of_birth] << "Date Of Birth can not be set for a future date!" | |
end | |
private | |
def check(record) | |
(record.date_of_birth < Date.current) | |
end |
This file contains hidden or 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
07 > (@paitent.date_of_birth).to_date | |
=> Thu, 03 Mar 2011 | |
ruby-1.9.2-p136 :008 > (@paitent.date_of_birth).to_date == Date.today | |
=> true | |
ruby-1.9.2-p136 :009 > (@paitent.date_of_birth).to_date == Date.yesterday | |
=> true | |
ruby-1.9.2-p136 :010 > (@paitent.date_of_birth).to_date == Date.tomorrow | |
=> false |
NewerOlder