class Commit < ActiveRecord::Base attr_accessible :comments, :committed_on, :committer, :project_id, :repository_id, :version validates :repository_id, presence: true validates :version, presence: true, uniqueness: {scope: :repository_id} validates :committed_on, presence: true has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy after_create :act_as_forge_activity # 项目中提交动态 def act_as_forge_activity self.forge_acts << ForgeActivity.new(:user_id => 2, :project_id => self.project_id) end end