Skip to content

Instantly share code, notes, and snippets.

@tonywok
Created October 11, 2010 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonywok/621083 to your computer and use it in GitHub Desktop.
Save tonywok/621083 to your computer and use it in GitHub Desktop.
class Assignment < ActiveRecord::Base
belongs_to :project
belongs_to :user
validates_uniqueness_of :project_id, :scope => :user_id
before_create :calculate_time_allocation
def calculate_time_allocation
self.time_allocation ||= (100 - user.reload.total_time_allocation)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment