What I want to do is destroy a specific ActiveRecord from jQuery, which is within an .html.erb file that has the record I want to destroy as an instance variable (@connection). I tried various attempts with jQuery.ajax, but nothing worked. Any help is much appreciated.
I thought the fix worked, but it didn’t. I got this, which works if I run it in the javascript console:
$.ajax({
type:"DELETE",
url:"<%= connection_path(@connection) %>",
success: function(msg){
alert("disconnected");
}
});
But when its supposed run in my javascript it does not. I’m so confused.
You’ll need to create the
destroyaction in your connection controller, which will receive the connection id. Then in your view call that action using@connection.idas the parameter.Edit
For the JQuery part, you can use something like this: