Created
February 21, 2013 03:37
-
-
Save thenanyu/5001832 to your computer and use it in GitHub Desktop.
Rials Validation
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 Invoice < ActiveRecord::Base | |
| validate :expiration_date_cannot_be_in_the_past, | |
| :discount_cannot_be_greater_than_total_value | |
| def expiration_date_cannot_be_in_the_past | |
| if !expiration_date.blank? and expiration_date < Date.today | |
| errors.add(:expiration_date, "can't be in the past") | |
| end | |
| end | |
| def discount_cannot_be_greater_than_total_value | |
| if discount > total_value | |
| errors.add(:discount, "can't be greater than total value") | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment