1class Projects_user < ActiveRecord:: Base |
|
|
|
3 validates :project_id, presence: true |
|
4 validates :user_id, presence: true |
|
6 validate :user_exists , on: :create |
|
7 validate :project_exists, on: :create |
|
9 private
|
|
11 def project_exists |
|
13 project = Project.find_by(id: project_id) |
|
14 if project == nil |
|
15 errors[:project] = "project belong to projects_user is not exist" |
|
16 end |
|
18 end |
|
20 def user_exists |
|
22 user = User.find_by(id: user_id) |
|
23 if user == nil |
|
24 errors[:user] = "user belong to projects_user is not exist" |
|
25 end |
|
27 end |
|
29end |