Created
November 5, 2010 12:42
-
-
Save masterkain/664081 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 Task < ActiveRecord::Base | |
belongs_to :category | |
belongs_to :project | |
validates_presence_of :project_id, :category_id | |
validates_with OvertimeValidator | |
scope :of_date, lambda { |date| where(:date => date) } | |
end | |
class OvertimeValidator < ActiveModel::Validator | |
def validate(record) | |
record.errors[:overtime] << "No more than 8 hours a day, please" if Task.of_date(self.date).map(&:amount).sum + self.amount > 8 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment