Created
May 17, 2010 13:26
-
-
Save rociiu/403752 to your computer and use it in GitHub Desktop.
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
# == 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