Skip to content

Instantly share code, notes, and snippets.

@bcardarella
Created June 9, 2011 06:00
Show Gist options
  • Save bcardarella/1016149 to your computer and use it in GitHub Desktop.
Save bcardarella/1016149 to your computer and use it in GitHub Desktop.
class Hour < ActiveRecord::Base
belongs_to :user
validates_with PunchclockValidator #defined in config/initializers/punchclock_validator.rb
validates_presence_of :role, :message => "can't be blank"
validates_associated :user
validates_numericality_of :manual, :allow_nil => true
validates_presence_of :start_time, :if => :punchcard?
validates_presence_of :manual, :if => :manual?
end
class PunchclockValidator < ActiveModel::Validator
def validate(record)
if record.start_time > record.end_time
record.errors[:base] << "Start time is after end time."
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment