Skip to content

Instantly share code, notes, and snippets.

@rociiu
Created May 17, 2010 13:26
Show Gist options
  • Save rociiu/403752 to your computer and use it in GitHub Desktop.
Save rociiu/403752 to your computer and use it in GitHub Desktop.
# == Schema Information
#
# Table name: experiences
#
# id :integer(4) not null, primary key
# doctor_id :integer(4)
# place_of_practice :string(255)
# year_start :integer(4)
# year_end :integer(4)
# created_at :datetime
# updated_at :datetime
#
class Experience < ActiveRecord::Base
set_table_name 'users'
class << self
def validates_is_higher(*attrs)
configuration = { :message => '"Year Start" should be greater than "Year End"', :on => :save }
configuration.update(attrs.extract_options!)
options = attrs.extract_options!.symbolize_keys
attrs = attrs.flatten
# Declare the validation.
send(validation_method(options[:on] || :save), options) do |record|
record.errors.add_to_base(configuration[:message]) unless record.send(attrs.first) <= record.send(attrs.last)
end
end
end
belongs_to :doctor
validates_presence_of :place_of_practice
validates_numericality_of :year_start, :greater_than => 0, :message => 'must be selected'
validates_numericality_of :year_end, :greater_than => 0, :message => 'must be selected'
validates_is_higher :year_start, :year_end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment