|
class Mission < ActiveRecord::Base
extend FriendlyId
friendly_id :title, use: :slugged
validates_presence_of :title, :slug
belongs_to :owner, :class_name => "User"
has_many :mission_agents, :dependent => :destroy
has_many :agent_steps, :through => :mission_agents
accepts_nested_attributes_for :mission_agents, allow_destroy:true
mount_uploader :cover_img, MissionCoverUploader
process_in_background :cover_img
def agent_position_count
return self.mission_agents.count
end
def confirmed_agent_count
return self.mission_agents.count
end
def check_for_completion
self.mission_agents.each do |agent|
agent.agent_steps.each do |step|
if step.completed == true || step.completed == nil
return false
end
end
end
self.update(status: 3)
return true
end
end
|