So this is related to another SO question (Why does destroy action trigger HTTP authentication in Production in Rails 3?) which I think is at the heart of that issue, but not sure how to do it.
Apparently my $.destroy()
is not being passed the requisite CSRF token.
But I am not sure how to include it.
This is my JS:
var compv = {
exists: true,
tools: {
exists: true,
csrf_param: null,
csrf_token: function() { },
clientError: function() { }
},
comments: {
exists: true,
updateView: null,
selectImage: null,
upvote: null,
edit: null,
cancelEdit:null,
downvote: null,
showVotes: null,
destroy: {
success: null,
error: null,
dialog: 'comment-destroy-dialog'
},
getUploadID: function(element) {
return $(element).parents("li").attr("data-upload-id");
}
},
steps: {
exists: true,
selectFn: {},
selectedClass: "selected-step",
selectableClass: "selectable-step",
selectedClient: {
element: null,
id: null,
stepType: "client",
ajaxSuccess: null
},
selectedProject: {
element: null,
id: null,
stepType: "project",
ajaxSuccess: null
},
selectedStage: {
element: null,
id: null,
stepType: "stage",
ajaxSuccess: null,
getID: function() {
return compv.steps.selectedStage.id;
},
displayCompare: function() {
window.open($(this).attr('data-url'), "_blank");
}
},
selectedUpload: {
element: null,
id: null,
stepType: "image",
primeUploadDisplay: null,
ajaxSuccess: null,
uploader: null,
noCloseDialog: false
}
}
};
compv.tools.csrf_param = function(){
return $('meta[name=csrf-param]').attr('content');
};
compv.tools.csrf_token = function(){
return $('meta[name=csrf-token]').attr('content');
};
This is my $.destroy()
$.destroy({
url: element.attr('data-destroy-url'),
success: mapping.success
});
Given that I am getting the appropriate csrf meta data in the above functions, how do I then pass it to the .destroy() ?
I tried adding compv.tools.csrf_token
, but the error I got is that compv
is not defined. The same thing happened when I did compv.tools.csrf_token()
.
Thoughts ?