class ProjectMembership < ActiveRecord::Base belongs_to :user belongs_to :project validate :ensure_account_member private def ensure_account_member unless user.member_of?(project.account) errors.add(:base, "This user is not a member of #{project.name}'s account") end end end