I have an ajax request that isnt reaching my backend function. The request gives a status of 200 and steps into the success but it never hits my backend controller method. In my response I get this:
Turbolinks.clearCache() Turbolinks.visit("http://localhost:3000/session/new", {"action":"replace"})
I dont get any errors in my Dev console. Any thoughts on how to solve this?
Rails version is 6, Turbolinks version is 5.0.1
This is my route in my routes.rb file
resources :analyses_groups, :controller => "analyses/groups" do
delete "remove_mitigation_mapping", on: :collection;
post "add_mitigation_mapping", on: :collection;
end
My ajax call is in my index.html.erb file
$(document).ready(function() {
$("button.delete_mapping_item").on('click', removeMapping);
});
var removeMapping = function (event) {
event.stopPropagation();
var button = $(this);
var mapping_type = button.data("mapping_type");
var mapping_index = button.data("mapping_index");
var mapping_name = button.parents("span").text();
if (confirm("Are you sure you want to remove " + mapping_name + "from " + mapping_type + "?")) {
$("#shade").show();
// Get mitigation_matrix_id
var row = $(this).parents("tr").parents("tr")[0]
var mitigation_matrix_id = $(row).find(".mitigation_matrix_id").text()
// Set up params for URL
var param_hash = {
"mitigation_matrix_id": mitigation_matrix_id,
"mapping_type": mapping_type,
"mapping_index": mapping_index,
}
$.ajax({
url: "/analyses_groups/remove_mitigation_mapping" + '?' + $.param(param_hash),
type: "DELETE",
success: function(data) {
console.log("success");
console.log(data);
button.closest("tr").remove();
$("#shade").hide();
},
error: function(data) {
$("#shade").hide();
}
});
}
}