30 lines
726 B
Ruby
30 lines
726 B
Ruby
class Missions_user <ActiveRecord:: Base
|
|
|
|
validates :mission_id, presence: true
|
|
validates :user_id, presence: true
|
|
|
|
validate :mission_exist, on: :create
|
|
validate :user_exist, on: :create
|
|
|
|
private
|
|
def mission_exist
|
|
|
|
mission = Mission.find_by(id: mission_id)
|
|
if mission == nil
|
|
errors[:mission] = "mission belong to Missions_user is not exist"
|
|
end
|
|
|
|
|
|
end
|
|
|
|
def user_exist
|
|
|
|
user = User.find_by(id: user_id)
|
|
if user == nil
|
|
errors[:user] = "user belong to Missions_user is not exist"
|
|
end
|
|
|
|
end
|
|
|
|
|
|
end |