2016-12-29 17:33:25 +08:00
|
|
|
class Missions_user <ActiveRecord:: Base
|
2016-12-26 12:13:59 +08:00
|
|
|
|
2017-01-02 10:57:57 +08:00
|
|
|
validates :mission_id, presence: true
|
2016-12-26 12:13:59 +08:00
|
|
|
validates :user_id, presence: true
|
2016-12-27 20:15:05 +08:00
|
|
|
|
2016-12-29 17:33:25 +08:00
|
|
|
validate :mission_exist, on: :create
|
|
|
|
validate :user_exist, on: :create
|
2016-12-27 20:15:05 +08:00
|
|
|
|
2016-12-29 17:33:25 +08:00
|
|
|
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
|
|
|
|
|
2016-12-27 20:15:05 +08:00
|
|
|
|
2016-12-26 12:13:59 +08:00
|
|
|
end
|