7 days of WordPress plugins, themes & templates - for free!* Unlimited asset downloads! Start 7-Day Free Trial
FREELessons: 16Length: 3 hours

Next lesson playing in 5 seconds

Cancel
  • Overview
  • Transcript

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.

Back to the top