1 00:00:00,540 --> 00:00:01,510 Hello and welcome. 2 00:00:01,530 --> 00:00:10,260 In this picture we are going to add another action to our post control and the tone we're going to add 3 00:00:10,380 --> 00:00:12,480 is a create action. 4 00:00:12,490 --> 00:00:21,810 So we're going to enable us to create a new post in our previous like show we did here from use in the 5 00:00:21,810 --> 00:00:23,220 form help. 6 00:00:23,220 --> 00:00:30,750 So we're looking at the form here you can see we've got a helper here which is post on the path. 7 00:00:31,110 --> 00:00:37,770 So what that does is it basically tells Real's to point the form. 8 00:00:37,760 --> 00:00:39,200 Today you are right. 9 00:00:39,360 --> 00:00:45,640 Patton associated with the post prefix. 10 00:00:45,690 --> 00:00:52,480 So if we look at this script we used to create the form to create the resources. 11 00:00:52,750 --> 00:01:02,510 When we did Real's routs and that showed us all the defined roles for our post results. 12 00:01:02,610 --> 00:01:11,100 So looking at the defined roots here we can see that the path that pulls post on the score path our 13 00:01:11,610 --> 00:01:21,960 tells Real's 2. the form to these you are a pattern associated with the post prefix and the form by 14 00:01:21,960 --> 00:01:26,720 default will send it pulsed request to that room. 15 00:01:27,120 --> 00:01:31,460 So these are the veres Type I request you to send a paused request. 16 00:01:31,460 --> 00:01:38,880 For example if we wanted to create a new pause it was sent create post requests if we wanted to add 17 00:01:38,940 --> 00:01:39,690 a new. 18 00:01:39,870 --> 00:01:49,400 It does that you want or edit it does that if you want to show unsewn saw the polls underscore PAFF 19 00:01:49,550 --> 00:02:00,120 helper is responsible for pointing the pointing rails to the relevant u r l which have been defined 20 00:02:00,300 --> 00:02:02,730 here so points it to the rutz. 21 00:02:02,940 --> 00:02:06,840 So if we try to say something now. 22 00:02:06,850 --> 00:02:11,070 So if I say type 2 I just say test 23 00:02:13,890 --> 00:02:17,020 body I say hello. 24 00:02:17,040 --> 00:02:21,100 If I try to say this now I should get an error click say. 25 00:02:22,530 --> 00:02:25,290 I'm expecting to get an error. 26 00:02:27,070 --> 00:02:30,080 Okay so you can see here I've got an error here. 27 00:02:30,500 --> 00:02:37,860 No my t's post slash new so you can see we got an error here. 28 00:02:37,900 --> 00:02:43,910 So the server is not happy and he has complained and let his feelings know. 29 00:02:43,920 --> 00:02:50,230 So basically what I've seen here the error messages sometimes are quite straightforward explanatory 30 00:02:50,290 --> 00:02:59,020 saying that we have to perform an unknown action the action create could not be found for the post control 31 00:02:59,020 --> 00:03:06,970 us so busy telling us that this is a post quantrell I hear we've got index methode index action new 32 00:03:06,970 --> 00:03:11,290 action but we haven't got action to create. 33 00:03:11,290 --> 00:03:14,250 So basically what we need to do is create one. 34 00:03:14,380 --> 00:03:23,890 So come here and type in def create of course when you enter your post it creates it. 35 00:03:23,890 --> 00:03:28,440 So you need a method or an action to take care of that. 36 00:03:28,450 --> 00:03:30,740 So we've got that done now. 37 00:03:30,790 --> 00:03:35,240 My indentation is not that brilliant but it doesn't really matter. 38 00:03:35,240 --> 00:03:37,240 We just want to get the code working. 39 00:03:37,490 --> 00:03:46,970 So now if I refresh all falling should should be okay now and give it a few minutes to refresh. 40 00:03:48,060 --> 00:03:56,780 Okay so now if my post again I shouldn't get any errors because I've now created this action called 41 00:03:56,790 --> 00:03:59,590 create cyclic currency. 42 00:03:59,700 --> 00:04:07,720 Nothing will happen but I should not get an error or you can see it returns back to the same page. 43 00:04:07,740 --> 00:04:18,390 The reason nothing happens when I resubmitted the page is because by default reals returns it to zero 44 00:04:18,390 --> 00:04:19,680 for error. 45 00:04:19,830 --> 00:04:21,830 What that means is that he's in no. 46 00:04:21,870 --> 00:04:25,530 No content response for an action. 47 00:04:25,560 --> 00:04:32,580 So if we don't specify what the response should be we just get he just returns to dippie to what we 48 00:04:32,580 --> 00:04:33,080 need to do. 49 00:04:33,080 --> 00:04:40,470 Now we need to we've just added to create action but we didn't specify anything about how the response 50 00:04:40,470 --> 00:04:41,370 should be. 51 00:04:41,640 --> 00:04:48,690 So what we need to do quote back into the controller and within the create action we should edit it 52 00:04:48,720 --> 00:04:55,230 to specify what type of response we are expecting when we submit the form. 53 00:04:56,370 --> 00:05:04,600 Ideally create action when you submitted should save the new post to the database. 54 00:05:04,710 --> 00:05:08,790 So before I head it be quick action. 55 00:05:08,810 --> 00:05:11,270 I just wanna explain something here. 56 00:05:11,430 --> 00:05:18,280 So when a form is submitted for this form when it is sub me to the fields of the form. 57 00:05:18,320 --> 00:05:26,040 So these are fields here and we've got title and we've got body the actual fields or the form are sent 58 00:05:26,850 --> 00:05:31,380 to the rails application as para methods. 59 00:05:31,590 --> 00:05:38,110 Okay so these parameters can then be referenced inside the controller actions. 60 00:05:38,280 --> 00:05:41,810 So a typical is to perform a task. 61 00:05:42,030 --> 00:05:48,640 You need to edit the create action here. 62 00:05:48,690 --> 00:05:51,600 I just need to for us to see what was submitted. 63 00:05:51,600 --> 00:05:54,150 I need to specify what should happen. 64 00:05:54,150 --> 00:05:58,580 So in here I am just going to tab down and typing. 65 00:05:58,710 --> 00:06:08,700 I want the form to render something so I'll see a render plain just going to end up playing along and 66 00:06:08,700 --> 00:06:12,960 do parramore sounds for parameters render programs. 67 00:06:13,140 --> 00:06:15,410 I'm going to put the symbol file Larry. 68 00:06:15,420 --> 00:06:19,650 Inside there are past posts. 69 00:06:20,310 --> 00:06:26,200 Okay and do a dot inspect. 70 00:06:26,360 --> 00:06:33,640 To what should happen when I asked resubmit for a tool outpoured what I've submitted in car like an 71 00:06:33,720 --> 00:06:37,660 object with to scour like a J sun object. 72 00:06:37,830 --> 00:06:40,070 So let me say that. 73 00:06:43,050 --> 00:06:45,930 Okay so let me submit the form again. 74 00:06:45,960 --> 00:06:54,950 Ah click refresh that and then put the title in again to see test. 75 00:06:54,990 --> 00:06:58,730 Just say hello and click save. 76 00:06:58,770 --> 00:07:02,190 You can see now we've got the parameters displayed. 77 00:07:02,200 --> 00:07:07,740 Come on like a sun object saw this clear was happening here. 78 00:07:07,740 --> 00:07:09,960 The rynd Method. 79 00:07:10,170 --> 00:07:19,800 This render method here is take in a hash with a key off plane. 80 00:07:20,240 --> 00:07:20,670 OK. 81 00:07:20,700 --> 00:07:22,620 So this is taking a hash. 82 00:07:22,620 --> 00:07:29,930 The key is plain and the value of paramus which is a prime it. 83 00:07:30,360 --> 00:07:32,200 Okay which is a post. 84 00:07:32,250 --> 00:07:33,280 Inspect. 85 00:07:33,420 --> 00:07:39,680 So we see whether value seen as prime is inspected less what is displayed here. 86 00:07:40,210 --> 00:07:49,510 The paramus Method is the object which represents the parameters or the fields which any time the form. 87 00:07:49,620 --> 00:07:55,110 Anything we intend the form is represented by the para rahm's object. 88 00:07:55,110 --> 00:08:03,450 So all the paramus metod returns an action controller which is a Param in those object which allows 89 00:08:03,450 --> 00:08:11,980 you to access the keys of the hash is in either strings or symbols in this equation. 90 00:08:12,000 --> 00:08:17,700 The only parameters that actually matters are the ones that we have submitted on the form which is the 91 00:08:17,700 --> 00:08:20,630 title and the body. 92 00:08:20,630 --> 00:08:25,680 So as you can see we got the but we suddenly turn the lafont been displayed here. 93 00:08:25,780 --> 00:08:28,410 This is not how we wanted to display later. 94 00:08:28,430 --> 00:08:29,670 Later we're going to be. 95 00:08:29,670 --> 00:08:34,320 The data is going to be saved in the database and retrieve from the database. 96 00:08:34,530 --> 00:08:39,280 We just want to at this stage to prove that we do what ever we submitted to the form. 97 00:08:39,570 --> 00:08:41,660 We can see it one way or the other. 98 00:08:42,000 --> 00:08:44,060 So that's it for this liqueur. 99 00:08:44,060 --> 00:08:48,180 This nature has taken a bit longer than expected so I do apologize. 100 00:08:48,180 --> 00:08:49,190 Thanks for watching. 101 00:08:49,190 --> 00:08:49,710 Bye for now.