app/controllers/participants_controller.rb
# Copies existing participants from a course down to an assignment
Copies existing participants from a course down to an assignment
Copies existing participants from a course down to an assignment
def inherit
    assignment = Assignment.find(params[:id])
    course = assignment.course
    @copied_participants = []
    if course
      participants = course.participants
      if !participants.empty?
        participants.each do |participant|
          new_participant = participant.copy(params[:id])
          @copied_participants.push new_participant if new_participant
        end
        if !@copied_participants.empty?
          undo_link("The participants from \"#{course.name}\" have been successfully copied to this assignment. ")
        else
          flash[:note] = 'All course participants are already in this assignment'
        end
      else
        flash[:note] = "No participants were found to inherit this assignment."
      end
    else
      flash[:error] = "No course was found for this assignment."
    end
    redirect_to controller: 'participants', action: 'list', id: assignment.id, model: 'Assignment'
  end
def inherit assignment = Assignment . find ( params [ :id ] ) course = assignment . course @copied_participants = [ ] if course participants = course . participants if ! participants . empty? participants . each do | participant | new_participant = participant . copy ( params [ :id ] ) @copied_participants . push new_participant if new_participant end if ! @copied_participants . empty? undo_link ( "The participants from \"#{course.name}\" have been successfully copied to this assignment. " ) else flash [ :note ] = 'All course participants are already in this assignment' end else flash [ :note ] = "No participants were found to inherit this assignment." end else flash [ :error ] = "No course was found for this assignment." end redirect_to controller : 'participants' , action : 'list' , id : assignment . id , model : 'Assignment' end
Copies existing participants from a course down to an assignment
Copies existing participants from a course down to an assignment
# Only display undo link if copies of participants are created