1class Mission < ActiveRecord:: Base
 
2
 
3    has_many :comments
  • remove trailing whitespace » rails_best_practices
4    
 
5    
 
6    validates :name, presence: true
 
7    validates :deadline, presence: true
 
8    validates :priority, presence: true
 
 9    validates :status, presence: true
 
10    validates :content, presence: true
 
 
12    validates :project_id, presence: true
 
 
 
15    validate :priority_is_among_valid_values
 
16    validate :status_is_among_valid_values
 
 
18    validate :project_exists, on: :create
 
 
20    private 
 
 
22        def priority_is_among_valid_values
 
 
24            if priority != 1 and  priority != 2 and priority != 3
 
25                errors[:priority] = "priority is not among valid values"
 
26            end
 
27        end
 
 
29        def status_is_among_valid_values
 
 
31            if  status != 1 and  status != 2 and status != 3 and status != 4
 
32                errors[:status] = "status is not among valid values"
 
33            end
 
34        end
 
 
36        def project_exists
 
37            #puts project_id
 
38            project = Project.find_by(id: project_id)
 
39            #puts project.inspect
 
40            if project == nil
 
41                errors[:project_id] = "project_id is not exist"
 
42            end
 
 
44        end
 
 
 
47end