Skip to content

Instantly share code, notes, and snippets.

@thenanyu
Created February 21, 2013 03:37
Show Gist options
  • Select an option

  • Save thenanyu/5001832 to your computer and use it in GitHub Desktop.

Select an option

Save thenanyu/5001832 to your computer and use it in GitHub Desktop.
Rials Validation
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