1class Project < ActiveRecord::Base
 
2  has_and_belongs_to_many :users
 
3
 
4  validate :require_at_least_on_user,on: :update # 
 
5  
 
6  validates :name, presence: true, length: { minimum: 1, maximum: 50 }, uniqueness: true
 
7
 
8  private
 
 9
 
10    def  require_at_least_on_user
 
11      if !users || users.size == 0  # size
 
12        errors[:users] = 'at least one user in the project'
 
13      end
 
14    end
 
15end