REST API in Ruby on Rails - Task app (Todo Controllers and routes)
Transcript
English (Auto-generated)
tutorial rest A. P. I. Movie or lose. So now we are going to try and create the controllers and subsequently the routes to complete our so we're gonna go about it is just like before goodness. So remember who created the models? Did something like generator instead of creating the first director use some models, right bruise, be something like ruse generates in generate border. Do they were passing some parameters that you created for us? So he said model, we're not going to create controller. Oh yeah. And then this time around the linear convention for this instead of in models, we use the singular word but in control as you use the plural version, we're starting with caps. So we don't need to pass any other private although we can see see if we want to have an index to want a new decks. If you create an index matter for us to want the shoe he wants to ensure with the gods. So it was you can look here, he's going to create it inside this folder for us service further to just watch as things change, it's not supposed to be issue. I don't know why still needs to start. Thank you. Okay. Okay. Uh huh. So apart from casino integrated, defined for us to produce controller. And then he also went on and created new out some top round gets to get tradition, that's the stage. No. Okay, that's one of them is going to be working a visit. So let's go back to our controller that was created so we need to you can see it's created the index. If we are not put us those parameters even that is too matters for us. So we're going to be needing it. So now I want to do is we need to treats we need to see some more methods here beginnings breeds how to create but I'm not going to. But what if you can't decide to use it, but I'm not this to create a method. We need to do something like Mhm. Created to do need to do something like we do equal to Mhm. Something like if you look at it, thank you. This is to do to do object. I need to do the new blah blah, blah, blah. I think I should follow this explained to you knew it is how you create a new object. So it's going to be something like something like uh to do because they just to explain follow suggestion. Yeah. Yes. Good of guilt because we are looking for title parents. Yes, it is what this what it's suggesting. So this um intelligence is made possible by a particular extension of the extension. Let's see the extension that means that possible in stores. I have you will be a race. So this extension will be arrested. Yes. So that's what makes it possible. Just going to have to check for and the rest inside these extensions. So that's what you fracture the most. So you're in place of this. Okay. We just see something like to do. you can see so we can also see I'd like to say this because he's going to win the social system instead of flashing is beautiful flash of dirt. Are you directing the object? You want to be doing this? Rather we are going to be rendering so what are we going to be rendering? We're going to be rendering Jason and and so tax, we will see do it. This is something like do you see Peter? Okay, don't do it. One of these militants. Mhm. You want to don't do this. In fact when you go to the medium skills talking to an exception and then we'll catch the exception. So let's see how this goes render Jensen data people's Oh forward. Okay, so let's see how that works. Sweet Judicial created here is going to be his initiative response. So um Really has some conventions for instead of seeing 2, 1 those two words don't worry automatically means it's simple mercy to two. So next week, which was going to happen. So before we can really test these out, I also need to create your routes. Now you need to understand something about how it works, raises an NBC. NBC. So by NBC means model views and control. So we started this tutorial by creating a model now because it is an A. P. Then the distance for views because it is an A. P. I There is no view layer but that we're going to be having endpoints that are going to be accessible from any other front end framework. So there's the dentist systems for controller controllers like then we are now and they're actually does it's not like he directs the other parts of the application. So the application the rails framework receives requests from your all to the request was on this controller. So he received the request from these routes. If somebody is making a request to a particular resource from here and then it lands here. So we're going to create the route that's going to so this is nobody reading this because this is generated for us. So to work for this particular route we're going to use I want to do something like something that was going to see like we're going to make a request or something like http gold coast local host for 3000 slash to do, which is going to be a post request. Going to make a first request. Yes. So that's what's really so I'm going to just comment just a comment. Mhm Let me know this information. So what else can you controller want to make your first three questions. Yeah. To hear there are different ways to go about writing around really makes it easy for us. So resources you what is it? Mhm. Exchange. So to do um So this student for now and when to come back to this later comments, sports. So what this is going to do is that is going to create gets and index to create roles for the index. He added the new and the updates and the it's and then deletes none of that. We're going to examine base. So let's the implication of this now is that if I go to my come here and Byron whose routes so you can see that all these ones that you see below here really generated or default rules that are created for different other actions. But it was that I just created no to do index, which is a pretty face in case we need some kind of so it doesn't mean to mark with him but this is the pattern. You are stupid. This you are a lotion. Yeah. And to get going to do you are a person. The number is the same thing. We thought that charge. Mhm Let's go back. So that's that's for that. So the only one the only the only the we've created creates pieces we are ready to create. We're going to create something records. So let's go ahead now and create. How do we create to do in an api there's no you're using that. There's no in irregular application. We have reform typing title, click on submit and then that's it. It's going to submit the form for us but in an A P I there is no form, there's no user interface rather we have some tools that are going to be able to make http requests And now we have one also to use this postman one of the most popular who's smart and to do that. We're going to so you just download boost man and then install postman or your system afterwards. Then we just do the folder and then we do this once. What's wrong? Sure. I'm about to make it whose request to what I want to I want to create created posts. Sure, that's true. So remember what what what speak. So this is um we're looking for to do and it's supposed to request. It's going to map to our creator to do this. Are you writing? That's what's good is going back. So let's make a how do you make a request onto our body? You can use any one is what? I'm not going to use them. Right. I'm going to use this for and it's too soon. What what what's in our patient requires from us? We need an army type require from what's the title? So we're going to pass it. It's going to be a strange it's so updated. First to do. Okay. So let's see if that works. So first of all I think we're here to start to serve us. That's right. Sometimes we don't even know You know what's 3000 for? 3000? That's where we are attaching the 3000 to eat what? So let's go ahead and see what happens. 3000 error. This is an initialized constant to do controller. Did you mean to reduce controller? So let's see what happens. Where did I write that when you search on controller. So what's the error? It gives us give us said a show controller announcing era. Nice view. This is telling us that we wrote the wrong thing in our routes. So let's go there and fix it surrounding Nero. So you can see here we're looking for resources collecting parts here is to see destroy your allies to realize our researchers to use to be somebody expecting me to say to do whereas that's single life. So if we go back to our routes here and there's the difference between what you already have here changes. You can see it has changed. I want to reduce your just so it should work. Was trying to do not that much to do. Small introduce because natural sense. Did you just two bad what life control you like to what does it do? What is using 96. Talking about our areas to do model too President standards when it is tied to just using Yeah, sure. And the wounds. Thank you. Presents. Sure. Again should dispute to be single. Let me see right when hash. Okay, produce controller. Mm I gotta work. Hmm. Strange. Something here. Mhm. Usually when you want to create a record should have something like try to Arabs title able to shoot me. I'm just trying to shoot soon. You're creating me record, She says a new one to do to be like the new like this and copy what's he need to do quotes, don't say something like this and then it should be titled and then something else like first um pass it like that like that as if you had couldn't where is this creature? What? For some reason So that's the proper way to do it but because we're using kitchen different towards so so she literally point and if you look at it very well give it to us as you become the response created to one and this is the data structure very well you realize what it is like that is the data you're looking at here despite everything out for us. So we're going to know if you want to see everything that's written. All the records are created. That's what goes into our index routes. If you look into our traditionally see that for the index if you control our index around these gates to do this. Sure, again jews. Mhm values they will render. Mhm. It's an object. Mhm. Mhm I do fish. The substitutes in case you wonder why we're attaching Acts in front of our variables. So in rails, attaching Acts makes means that you are creating and stands variable variable so it means that which if you add add to it in either anywhere in the application you can easily access, you can have access to in but in variable that is declared starting starting with that if you were dealing with a moderate application we could actually assess this from this. Yeah because it's an ep I may not may not be too significant because without it to still work for it but we just follow standard by living with us. Don't always have to add anyways to see for example like I didn't I didn't attach it for a lesson like this. First of all you can see it and let's go and test. Now this was for posting that is creating a request. Let's see what so this step around she gets I think that's only need for here percent. It was first. So like I said earlier we don't actually have to make it act because just a value to see what's right and it still works right. It was just good practice too. He was hurt. Mhm. No we created our index treated our. Mm hmm method issue method is responsible for fetching one record. So if you look here, see the ship issue method and you can see that it's fun. You are ready to introduce with a parameter I. D. Me too remind you. Apart from thank you guests can also begin on your but soon. Yes you do. He would George. So it's not just it's not just a person that can do that. So um now we need to get one record and one record just is see the idea is one you need to find the record with. No because we don't have we don't have anything controller. If we didn't put this shoe controller here it would throw an error which we don't need to do. Oh yeah sure she could not be for it for to use controllers hasn't been. It gets worse. So guess what we do for sure. Mhm. Brain she where do we get out with Remove This 1? Get this one out. This one is in the programs is going to be going to be studying the harems hush firearms harsh. Right. The hash honestly work. It would be harsh. So let's parents is just like you should go to something like right. Mhm. He's working I was actually quite supervises this I. D. Parameter use or switch something like this. So I said this I. D. Parameter. No idea. So it can either be a symbol or string. Strong two explains. We find that's and using from Mac we need to be fine enemies. So with this we should be able to get our right. Just that up with me. What she did was people's so where did you realize that take this? He was 200 by default considered a billion students here. We'd always pass. Okay. Okay okay. Yeah so it's like the same. It's okay okay we're not too so let's try it again. Water from I'm not easy between this and she was take note you find that this data is an object values are just one item. But when I see it's an area of objects that your collection. Mhm. Let's continue by creating your dicks mental edge. So in the orbit method. First of all we need to we need to find him. And I thought we need to update before we talk about updating it. So how do we get the objects? We need to update. So the same way we need to do to do peace this guy. This is our trying to be can you see resting Children? You see? Right. Mhm. Biggs like and what do you want to beat? Want your date by two. What's his new album? Did you find it? When do you firearms? It's thank you. So here we go I guess around me sir. Okay sir. Absolutely. And Mhm. Paper bye ratios from so update actually update actions to for a T. T. T. Birds. If we say two for 2 output. Well if we say 200 which is okay we're going to be getting something out. Mm It's so who's that? Let's say boot because remember when I shoot you get that time. So this time around for decades. But the updates method We're going to be using either parchment whichever one this is running more conventional but let's try this let's change the value of you want to do a bit. Yeah so there's a problem nor as much is proved to do. You're out much as let's strike much much as french. There's not. Oh sorry we didn't pass any parameter so we need Sure I make that true actually. And you can see dictated for us. So if we go back here and I'll check all of you take the consequence. It has changed Forget only one parameter right now that's true to us. It was in the parameter. Sure nurses to delete. So before we go on to delete let me create one more record second post dominantly circum post posts of course. Mhm. Mhm. Just quickly. Mhm. Mhm. Okay. I'm going to create it. You can see all eternity to us. So if we come back and you see all the introduce that have been created. We have three items. So We're going to try and delete this i. d. three. So the same thing we did in your kids. Let's try and handle destroyed because got you. It's almost like it creates. What are we going to try and find? We need to find something a little like this. Right? Yeah. Then which? Mhm Brenda. Okay Jason to destroy to destroy. I just want you just like your bits. Right. Yeah sure. And just no contents. Right? No content. We can also decide to refuge, render an object that wouldn't destroy contents with this. We should be able to destroy any parameter. So you suggest in physics and I'm just trying to do this. Just so as not to board, you are going to make it too complex and scary is that there are more complex things that you need to take note off. But this I'm just trying to introduce you to the simple crowd functionality. It would be so let's destroy. Let's try and it's something they were now looking for. The delete. You need to dilute the i. d. three and then That's all we need to do. I did three tool for but here see you can see we have three of them this this so it's it's no longer there successfully depicted. That's that's a simple crowd for her two DUIs so I'm going to stop this for now. This is glad you're getting too long already. And then next we'll move on to our clients, clients, sorry, not Quiet items, items, Yes, items. Model items. Controller school, That's that about that for this particular one. We'll see you next day