4.5 Delete Edges
In this lesson we'll give users the ability to delete edges.
1.Introduction1 lesson, 01:12
2.Application Setup2 lessons, 17:25
3.Public Area7 lessons, 1:37:56
4.User Section5 lessons, 1:04:12
5.Conclusion1 lesson, 00:31
4.5 Delete Edges
Hi. In this episode we'll implement deletion of edges. So first, let's go to edges.html file. And here we click in on the list item itself. So let's remove it to the name itself. So we have span. And we remove the ng-click from here to here like this. And right here let's add anchor tag with ng-click=*deleteEdge()* and we call Delete. And of course we need to provide what edge we want to delete, so the current edge. So if you go to browser you can see now that we have delete, and now clicking is not available to all the least item, but only on the name. Which is more proper. So now we need to create this edge delete. So we go to edges.gs. And right here on scope, let's define delete edge. There's a function and it takes edge itself. So to delete it, it's extremely easy. We just do edge dot and delete method which provided by the resource. But for this to work we need to introduce a little change. So let's have a look right now. If we go back to browser. Let's open network here. And if we click on delete, you can see that we have the delete request to HS API, but there are no parameters and there is no ID here. So we need to provide the ID for that. We go to service edges. And in here where we have the resource, we add id like this. And then we need to provide the object in which we specify what this id means, where to take this id from. And we use this syntax to tell Angular that we just take the id attribute from the object. So now, after this change, if we click on delete, you'll see that delete request sent with the ID, okay? That's great. So now, we need to go to our Rails application. So we go, first of all, we go to routes, and add here destroy route. Next, we go to Edges_controller.rb. And create, here, destroy action. And inside of this destroy action we, first of all, find, by params, id, the edge. Then we delete it. And then we render JSON response. Okay. And that's all that we need to do. If we go to browser right now and click on delete, it will delete it from the server and from the list here. Quite nice. So in this episode, we saw how we can easily delete records from the server and from the collection on the front hand. So, that you very much for your time and see you in the last episode of this course.