1 00:00:00,600 --> 00:00:02,330 Hello and welcome in this chair. 2 00:00:02,340 --> 00:00:07,080 We are going to try and see that are in B control. 3 00:00:07,410 --> 00:00:17,310 In a previous Lakeshore we created a model so we're going to do how it is meant to create action to 4 00:00:17,310 --> 00:00:20,760 reflect the new model that was created. 5 00:00:21,120 --> 00:00:30,260 So make sure you are him the post on this call control file and you can see this is the create action. 6 00:00:30,270 --> 00:00:36,690 We just need to our members since we've created a model at the moment what is doing is just rendering 7 00:00:36,690 --> 00:00:43,360 whether it's posted on the form is meant the net rendering it as an object like this. 8 00:00:43,380 --> 00:00:47,530 So we want it to render to the database via that model. 9 00:00:47,550 --> 00:00:49,860 So I'm just going to comment that out. 10 00:00:49,860 --> 00:00:54,010 You can delete it if you wish to do so but come in today for now. 11 00:00:54,240 --> 00:00:55,730 We just had some. 12 00:00:55,740 --> 00:00:59,280 I'm going to start by adding it variable and variable. 13 00:00:59,280 --> 00:01:02,880 I'm going to add I'm going to call it pause. 14 00:01:03,240 --> 00:01:07,410 So this is the same board to had variable in Ruby. 15 00:01:07,410 --> 00:01:12,000 So you just look at full of by paused in law case. 16 00:01:12,270 --> 00:01:21,550 I'm going to set that to equal to OP Keith Post dot new. 17 00:01:23,490 --> 00:01:24,750 N n t. 18 00:01:24,770 --> 00:01:38,990 Parent disease inside the person who sees half passing nipa trumps an ad and every column and then passing 19 00:01:39,080 --> 00:01:42,440 the post object. 20 00:01:45,100 --> 00:01:47,210 So what I've done here. 21 00:01:47,350 --> 00:01:57,170 That line of code basically any time you create a model you have to initialize the model you uninitialised. 22 00:01:57,190 --> 00:01:59,570 You've seen its attributes. 23 00:01:59,830 --> 00:02:08,740 So here be the attributes here are automatically mapped to the respective database columns so these 24 00:02:08,740 --> 00:02:20,620 two columns in a database which is title and the body and we represent in that we're the paramus and 25 00:02:20,620 --> 00:02:27,720 then the post that will give us the values of the columns in the database table. 26 00:02:28,330 --> 00:02:37,450 Another thing we can do is add on another variable that will be responsible for saving the module in 27 00:02:37,450 --> 00:02:38,820 the database. 28 00:02:39,040 --> 00:02:41,090 So we're just going to add that variable now. 29 00:02:41,130 --> 00:02:50,110 So we do at the time pick the word Post dot see. 30 00:02:51,160 --> 00:03:00,160 So this is what will save the data into the database using the model and then once it's been safe you 31 00:03:00,160 --> 00:03:05,140 want to be able to redirect it back somewhere so you do redirect 32 00:03:07,840 --> 00:03:20,770 on the score to 1 to redirect it back to the post variable at ports. 33 00:03:22,460 --> 00:03:25,350 I just want to create a space between that with the one hole. 34 00:03:25,480 --> 00:03:25,950 Okay. 35 00:03:26,120 --> 00:03:31,360 So read did underscore to at this post variable. 36 00:03:31,780 --> 00:03:39,510 So this read death rate here is going to redirect the user to the show action. 37 00:03:39,610 --> 00:03:45,550 We've not defined the show action yet but that's where it will redirect the user to something I want 38 00:03:45,550 --> 00:03:46,510 to point out here. 39 00:03:46,540 --> 00:03:51,940 Notice here we set this up pause variable two equals to pause new. 40 00:03:52,090 --> 00:04:02,440 And the reason we've got the P in upper case everything is capitalize is that it is referred to as a 41 00:04:02,470 --> 00:04:03,100 class. 42 00:04:03,100 --> 00:04:04,060 It is a class. 43 00:04:04,060 --> 00:04:07,290 That's why it is capitalized. 44 00:04:07,510 --> 00:04:18,680 So we are actually referring to V post that defined n bit cap models article Dort are B. 45 00:04:18,860 --> 00:04:19,350 All right. 46 00:04:19,360 --> 00:04:26,240 So we could post on this yeah to the HARP on the score models. 47 00:04:26,260 --> 00:04:34,570 If you go to aps and then go to modules and post B were referring to this class. 48 00:04:34,570 --> 00:04:42,790 This is a class where a to you can seise upper case P here so that's why we've got the upper case here. 49 00:04:42,820 --> 00:04:48,490 Thus the fear of the post it is referring to. 50 00:04:48,490 --> 00:04:54,110 So let's see and try and submit our form and see what happens. 51 00:04:54,280 --> 00:05:00,380 So we refresh this week in gowe form back. 52 00:05:01,900 --> 00:05:02,850 So this is our form. 53 00:05:02,860 --> 00:05:08,910 So let me just try and post something and I do expect to get an error. 54 00:05:09,550 --> 00:05:13,290 Click save and see what happens. 55 00:05:13,690 --> 00:05:16,660 So you can see we are getting an error here. 56 00:05:16,660 --> 00:05:18,240 Let me just expand the Thera. 57 00:05:18,550 --> 00:05:23,260 So is saying active model for the entire trip is the reason we're getting this error is that we've not 58 00:05:23,660 --> 00:05:31,320 had fully defined any special fields full of post so we don't live in peoples minds. 59 00:05:31,330 --> 00:05:36,130 We must define the feel we dont want people to just post anything they like. 60 00:05:36,160 --> 00:05:45,640 So if the security issues that we need to address so Real's has several security features that helps 61 00:05:45,640 --> 00:05:53,260 you right seek your application so when you are run into one of those features like we can see here 62 00:05:53,260 --> 00:05:59,480 on the screen may actually called strong prime it is what that does it out to be. 63 00:05:59,500 --> 00:06:09,600 He requires all reals is telling us to tell it exactly what parameters we are going to allow in to harm 64 00:06:09,610 --> 00:06:18,490 a controller actions so we need to tell it what we have to do is create a private method or action that 65 00:06:18,490 --> 00:06:27,310 can only be accessed from this class so when a method is made private It cannot be accessed outside 66 00:06:27,520 --> 00:06:31,000 the class so you need to create a private metal. 67 00:06:31,020 --> 00:06:35,460 You type in the word private. 68 00:06:35,600 --> 00:06:43,020 Okay and then here then you then define do a diff to define. 69 00:06:43,540 --> 00:06:49,680 Then I'm going to call it post on the score. 70 00:06:49,690 --> 00:06:53,200 Programs or the parameters. 71 00:06:53,530 --> 00:07:03,530 And here I'm going to specifying some values and when I say firearms do not require so I am setting 72 00:07:03,550 --> 00:07:19,720 the feels that the form will require and then empathises is on typing post and then here do not permit 73 00:07:20,620 --> 00:07:26,960 which means these other fields are permitted or fields or columns permitted. 74 00:07:27,280 --> 00:07:44,710 And then you do a call on the title we want the title comma space and there we also want the body so 75 00:07:44,770 --> 00:07:47,740 to call on unban. 76 00:07:48,370 --> 00:07:48,930 But the. 77 00:07:50,560 --> 00:07:55,410 And we need to end the methot typing end as to end it. 78 00:07:55,640 --> 00:08:04,340 So now that we've defined the we defined it created this private method here and we've got this action 79 00:08:04,340 --> 00:08:15,680 here called programs we have to amend the variable here to reflect what we have set here and the way 80 00:08:15,680 --> 00:08:22,070 we do that where we've got Post he to pause and cool down new. 81 00:08:22,380 --> 00:08:23,740 So we're going to keep passing. 82 00:08:23,780 --> 00:08:28,650 We're going to change this because we've got we're going to get the value from here. 83 00:08:28,790 --> 00:08:35,810 So we changed that from paramus Depp to post 84 00:08:38,480 --> 00:08:41,030 on the score. 85 00:08:41,580 --> 00:08:43,060 Paramount's 86 00:08:45,880 --> 00:08:53,460 okay because we've already defined it here so we're picking the values from here and amended it there. 87 00:08:54,410 --> 00:09:03,410 So now if we save and then go back and refresh half form or fully that we should now be able to save 88 00:09:03,860 --> 00:09:06,380 data to the controller. 89 00:09:07,250 --> 00:09:14,710 So led to a test and got to turn to code test and anybody else has called a textureless to save post. 90 00:09:14,840 --> 00:09:18,640 Hopefully we should not get the error. 91 00:09:20,040 --> 00:09:23,660 Actually yes we have gotten there and it's a valid error. 92 00:09:23,680 --> 00:09:27,250 The reason we have got the error is is clearly obvious. 93 00:09:27,680 --> 00:09:35,700 We have not created the shule action inside the post quantrill So this is a post controller. 94 00:09:35,840 --> 00:09:38,050 He can see there's no issue here even. 95 00:09:38,170 --> 00:09:45,590 We got his save here we've told it to read there it took pause which is this show we haven't defined 96 00:09:45,590 --> 00:09:46,350 this show here. 97 00:09:46,370 --> 00:09:52,910 That's why we get in error so I'm going to end this lecture here in the next lecture. 98 00:09:52,910 --> 00:09:58,830 Will had the Schul action to the post controller. 99 00:09:59,090 --> 00:10:01,020 Many thanks for watching by.