<commit_before>$(function(){
  $("#all-students-table").on("change", ".teacher-drop-down", updateTableFromDropDown);

  $("#all-students-table").on("submit", ".add-form, .remove-form", addStudent)
});

var updateTableFromDropDown = function(){
  var $that = $(this);
  var studentUrl = $that.parent().attr('action');
  var selectedTeacherId = $that.val();
  var url = studentUrl + "/teachers/" + selectedTeacherId;
  $.ajax({
    method: "patch",
    url: url
  })
  .done(function(data){
    var IDOfRowToReplace = $(data).attr("id")
    $('#' + IDOfRowToReplace).replaceWith(data);
  });
}

var addStudent = function(event){
  event.preventDefault();
  var $that = $(this);
  $.ajax({
    url: $that.attr('action'),
    method: "patch"
  })
  .done(function(data){
    var IDOfRowToReplace = $(data).attr("id");
    console.log($("#all-students-table").parent().attr("id"))
    if ($("#all-students-table").parent().attr("id") != "teacher-profile-students-table") {
      $('#' + IDOfRowToReplace).replaceWith(data);
    } else {
      $('#' + IDOfRowToReplace).remove();
    }
  })
}<commit_msg>Fix row breakage in other ajax done<commit_after>$(function(){
  $("#all-students-table").on("change", ".teacher-drop-down", updateTableFromDropDown);

  $("#all-students-table").on("submit", ".add-form, .remove-form", addStudent)
});

var updateTableFromDropDown = function(){
  var $that = $(this);
  var studentUrl = $that.parent().attr('action');
  var selectedTeacherId = $that.val();
  var url = studentUrl + "/teachers/" + selectedTeacherId;
  $.ajax({
    method: "patch",
    url: url
  })
  .done(conditionallyReplaceRow);
}

var addStudent = function(event){
  event.preventDefault();
  var $that = $(this);
  $.ajax({
    url: $that.attr('action'),
    method: "patch"
  })
  .done(conditionallyReplaceRow)
}

var conditionallyReplaceRow = function(data){
  var IDOfRowToReplace = $(data).attr("id");
  if ($("#all-students-table").parent().attr("id") != "teacher-profile-students-table") {
    $('#' + IDOfRowToReplace).replaceWith(data);
  } else {
    $('#' + IDOfRowToReplace).remove();
  }
}
{'fraction_non_alphanumeric': 0.21557454890788225, 'fraction_numerical': 0.0, 'mean_word_length': 4.215346534653466, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6871572', 'n_tokens_mistral': 711, 'n_tokens_neox': 713, 'n_words': 120}