1 00:00:00,740 --> 00:00:01,750 Hello and welcome. 2 00:00:01,750 --> 00:00:11,650 In this life sure we are going to add the action that will enable or create comments for our books. 3 00:00:12,230 --> 00:00:15,920 So we're going to do this inside be comments controller. 4 00:00:16,190 --> 00:00:24,110 So if you just navigate to where your controllers are which is uncanny upstair acri controller and then 5 00:00:24,140 --> 00:00:25,370 comments. 6 00:00:25,460 --> 00:00:30,640 So this is where we are going to create our action. 7 00:00:30,680 --> 00:00:37,700 So the first action I'm going to create here just kind of sat down. 8 00:00:37,790 --> 00:00:45,130 I'm going to define a create method so you do d.f. and bend the word create. 9 00:00:46,970 --> 00:00:48,280 And then end it. 10 00:00:48,590 --> 00:00:59,990 So before I add anything I want to create a private method that only be accessible from the class. 11 00:01:00,260 --> 00:01:13,240 So to define a private metate he just type in the word private space and then followed by deaf and then 12 00:01:13,460 --> 00:01:21,140 comment thus the name am given to it on the score power Rams. 13 00:01:22,580 --> 00:01:26,850 Just like we did with the post quantrell. 14 00:01:27,530 --> 00:01:34,550 I'm going to just add some values here so I'm going to see Pat ramps. 15 00:01:36,010 --> 00:01:44,350 Don't require So these are the fields that will be required for the comments form. 16 00:01:46,270 --> 00:01:56,940 And will grab that empathises and add a quill on then typing the word comment. 17 00:01:57,500 --> 00:02:01,120 I'm good as both at what we are going to allow. 18 00:02:01,280 --> 00:02:03,940 So I'm going to pair meet. 19 00:02:07,410 --> 00:02:12,180 Impaired folded depending on what you specified when you created the model. 20 00:02:12,560 --> 00:02:16,070 For me I specified just a name. 21 00:02:17,450 --> 00:02:22,260 So whatever a name you specify it is what you'd need to enter comma. 22 00:02:23,070 --> 00:02:28,300 Space call on an also specified is a body. 23 00:02:29,940 --> 00:02:30,810 And then are yours. 24 00:02:30,920 --> 00:02:32,880 And Nat. 25 00:02:33,860 --> 00:02:36,570 Okay so now they're back in place. 26 00:02:36,570 --> 00:02:43,340 I can go inside the create methods and just had some various books. 27 00:02:43,350 --> 00:02:47,150 I'm going to add the post variable. 28 00:02:48,680 --> 00:02:54,120 Will look post equal to the submitted post model. 29 00:02:54,140 --> 00:02:57,120 You can identify with a capital P. 30 00:02:58,740 --> 00:03:00,110 So a B post. 31 00:03:00,150 --> 00:03:01,540 Find. 32 00:03:05,600 --> 00:03:07,510 And empathises. 33 00:03:08,110 --> 00:03:12,380 I'm going to add para ohms. 34 00:03:14,590 --> 00:03:17,350 Inside them going to add. 35 00:03:18,900 --> 00:03:20,480 The Post. 36 00:03:21,680 --> 00:03:23,110 So what. 37 00:03:23,110 --> 00:03:26,010 The value it would take is the post I d. 38 00:03:26,010 --> 00:03:35,390 So we need to post I.D. so that we know which post we are adding comments to make so we need to do is 39 00:03:35,480 --> 00:03:41,350 add a comment variable and do that. 40 00:03:43,300 --> 00:03:44,310 Comment. 41 00:03:44,660 --> 00:03:48,190 And will a set back two equals two. 42 00:03:50,090 --> 00:03:51,730 The posed variable. 43 00:03:57,610 --> 00:03:58,600 Okay. 44 00:03:59,560 --> 00:04:00,680 DOT. 45 00:04:02,430 --> 00:04:04,220 Comments. 46 00:04:06,740 --> 00:04:09,770 Dot Creed's. 47 00:04:12,540 --> 00:04:24,140 And in parentheses we're going to pass in this here that we create so begin to comment on the score 48 00:04:24,200 --> 00:04:30,530 prompts that we pass him this in their necks and we need to do. 49 00:04:30,530 --> 00:04:31,960 We need to redirect. 50 00:04:32,000 --> 00:04:38,340 Once a comment has been created we want to redirect the user somewhere else or would typee redirect. 51 00:04:42,390 --> 00:04:52,780 On the score to specify where we direct in them to so with their it in them to the post on the score 52 00:04:52,810 --> 00:04:54,120 PAFF. 53 00:04:55,620 --> 00:04:57,630 And inside the pen this is. 54 00:04:57,640 --> 00:05:01,300 We pass in the post variable. 55 00:05:04,510 --> 00:05:07,450 Okay that should do it. 56 00:05:07,590 --> 00:05:13,810 Save that bisch LEARN Let's do some testing before we can test. 57 00:05:13,820 --> 00:05:18,980 We need to commence to show one's comments someone's left a comment. 58 00:05:18,980 --> 00:05:21,490 We want the comments to show. 59 00:05:21,770 --> 00:05:26,520 So to do that we need to go to D sure V you came within the post. 60 00:05:26,520 --> 00:05:31,210 So this is a post on the views post when they click on the show for you. 61 00:05:31,240 --> 00:05:39,790 And we need to add somewhere that would display the comments or. 62 00:05:39,830 --> 00:05:43,280 So what I'm going to do are just on the base a chart tag here. 63 00:05:43,280 --> 00:05:54,200 I'm going to just add add it so I've added decode here that will enable the comments to show in the 64 00:05:54,230 --> 00:05:54,530 sure. 65 00:05:54,540 --> 00:05:59,210 P So this is what I have added on. 66 00:05:59,330 --> 00:06:02,920 So basically here we have the post variable here. 67 00:06:02,980 --> 00:06:09,570 Notice after the percent here there is no it was to a because I'm not output in any form. 68 00:06:10,210 --> 00:06:12,530 But here I have implemented the loop so what. 69 00:06:12,530 --> 00:06:13,310 This should happen. 70 00:06:13,310 --> 00:06:18,120 It will loop through each comment and inside between the piping. 71 00:06:18,160 --> 00:06:23,900 Pass in the comment and wrapped it round the div here so it will have a D. 72 00:06:23,940 --> 00:06:25,900 I've given the div a class of. 73 00:06:25,910 --> 00:06:28,210 Well this is a boson trap class. 74 00:06:28,600 --> 00:06:30,470 And here this. 75 00:06:30,470 --> 00:06:37,990 Here is the name I've said within the model so depending what yours this fields's call username or whatever 76 00:06:38,160 --> 00:06:42,910 you should add that there are more that will do when the comment is made. 77 00:06:42,910 --> 00:06:49,260 It will make whoever has left the comment to give the name it Balde name to make it. 78 00:06:49,310 --> 00:06:51,790 That's what the strong tag does. 79 00:06:52,400 --> 00:06:55,040 And then we've got the comment here. 80 00:06:55,070 --> 00:06:56,960 OK we've got this here. 81 00:06:57,470 --> 00:07:02,580 The percent here which is the quote with said that that's going to put something. 82 00:07:02,810 --> 00:07:06,280 The Bears equals the next so the percent Emens use. 83 00:07:06,290 --> 00:07:09,190 But you are expecting an output. 84 00:07:09,310 --> 00:07:09,770 See. 85 00:07:09,800 --> 00:07:12,850 This will output the content of the body. 86 00:07:13,190 --> 00:07:15,800 And here's what we expect in an output tool. 87 00:07:15,800 --> 00:07:23,840 I'll put the name of the person live in the comment and wrap this here in a div here and then here we 88 00:07:23,840 --> 00:07:26,470 are ending what we started here. 89 00:07:26,480 --> 00:07:31,430 The percent here and this is the end of the list saved that. 90 00:07:31,990 --> 00:07:35,550 And we should be able to add a comment. 91 00:07:36,160 --> 00:07:42,470 Let's go back to our blog um as can a refresh just to make sure there's no errors. 92 00:07:42,520 --> 00:07:43,940 Let's test this out. 93 00:07:44,270 --> 00:07:47,080 I'm going to add a comment name our just saying 94 00:07:50,460 --> 00:07:51,600 blue line 95 00:07:54,700 --> 00:07:56,330 learning. 96 00:07:59,050 --> 00:08:00,680 Body o saying. 97 00:08:07,440 --> 00:08:09,660 Great post. 98 00:08:13,780 --> 00:08:14,880 Quick create. 99 00:08:15,120 --> 00:08:16,310 And if everything works out. 100 00:08:16,330 --> 00:08:17,930 Oh excellent is working. 101 00:08:17,950 --> 00:08:19,100 So there you go. 102 00:08:19,420 --> 00:08:22,190 So that's blue lime learnin. 103 00:08:22,330 --> 00:08:23,860 Who's left the comment. 104 00:08:23,890 --> 00:08:25,180 And this is what they've said. 105 00:08:25,180 --> 00:08:27,210 Great post fantastic. 106 00:08:27,220 --> 00:08:31,150 So are we now we're able to add comment at the moment. 107 00:08:31,150 --> 00:08:34,010 We can't delete comment because we want to be a book. 108 00:08:34,150 --> 00:08:40,990 We want to be able to delete comments as well so we will implement that in subsequent lectures from 109 00:08:40,990 --> 00:08:41,480 hell. 110 00:08:41,650 --> 00:08:44,380 Thanks for watching and bye for now.