1class Missions_user <ActiveRecord:: Base |
|
|
|
3 validates :mission_id, presence: true |
|
4 validates :user_id, presence: true |
|
6 validate :mission_exist, on: :create |
|
7 validate :user_exist, on: :create |
|
9 private
|
|
10 def mission_exist |
|
12 mission = Mission.find_by(id: mission_id) |
|
13 if mission == nil |
|
14 errors[:mission] = "mission belong to Missions_user is not exist" |
|
15 end |
|
18 end |
|
20 def user_exist |
|
22 user = User.find_by(id: user_id) |
|
23 if user == nil |
|
24 errors[:user] = "user belong to Missions_user is not exist" |
|
25 end |
|
27 end |
|
30end |