Created
June 9, 2011 06:00
-
-
Save bcardarella/1016149 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
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 |
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
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