Skip to content

Instantly share code, notes, and snippets.

@dannymcc
Created August 1, 2012 22:28
Show Gist options
  • Select an option

  • Save dannymcc/3231264 to your computer and use it in GitHub Desktop.

Select an option

Save dannymcc/3231264 to your computer and use it in GitHub Desktop.
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