1
00:00:00,960 --> 00:00:01,800
This video.

2
00:00:01,800 --> 00:00:07,290
And then the next one we are going to implement updating of a post.

3
00:00:07,320 --> 00:00:13,760
The concept going to be the same as updating the profile page of a user.

4
00:00:13,770 --> 00:00:19,220
So the first step is that we need to have the form when we click on edit.

5
00:00:19,230 --> 00:00:24,840
So let's get back to homepage and let's look at the post that belongs to me.

6
00:00:25,050 --> 00:00:28,650
And there is no post that belongs to me at the moment.

7
00:00:28,680 --> 00:00:35,880
If I go to my profile, you can see that I have no posts, so let me go ahead and create one before

8
00:00:35,880 --> 00:00:36,860
I continue.

9
00:00:36,870 --> 00:00:41,070
And you can see that for this we have lost the CSS for this.

10
00:00:41,070 --> 00:00:43,800
But don't worry, you fix it as you move on.

11
00:00:56,080 --> 00:01:00,400
Now I have one post created by me that is Iman.

12
00:01:00,850 --> 00:01:07,000
If I go to my profile page, you can see I have one post being created.

13
00:01:07,120 --> 00:01:15,050
So if I go to homepage and click on that, I will see the edit and then the update.

14
00:01:15,070 --> 00:01:23,020
So the logic here is that when I click on this edit, I want to open a form and we are going to use

15
00:01:23,020 --> 00:01:25,270
the same form for adding posts.

16
00:01:25,270 --> 00:01:27,690
So let's go ahead and then duplicate that.

17
00:01:27,700 --> 00:01:33,490
So inside views and posts and add posts.

18
00:01:33,520 --> 00:01:37,030
Let me copy and paste and change.

19
00:01:37,870 --> 00:01:40,990
The name to update post.

20
00:01:44,170 --> 00:01:44,490
All right.

21
00:01:44,580 --> 00:01:49,530
That and then the title is going to be post update.

22
00:01:50,550 --> 00:01:56,970
Likewise here as update post, we have the error.

23
00:01:56,970 --> 00:01:58,260
Everything is in place.

24
00:01:58,260 --> 00:02:00,990
So what has left is about the value.

25
00:02:01,110 --> 00:02:04,950
The next step is that we need to render this form.

26
00:02:04,950 --> 00:02:07,200
So how are we going to get it done?

27
00:02:07,290 --> 00:02:16,680
Remember, for this form, we want to populate the existing data of the posts so inside the root, or

28
00:02:16,680 --> 00:02:19,760
we can create that one inside the controller.

29
00:02:19,770 --> 00:02:25,440
So I think for business logic it must be in the controller and other one.

30
00:02:25,440 --> 00:02:27,900
I can put it inside the root.

31
00:02:27,900 --> 00:02:35,460
So here, let's go to the root instead, which is root post and post root here.

32
00:02:35,640 --> 00:02:43,500
So I'm going to create one root to get a form there going to be as post root, don't get.

33
00:02:44,580 --> 00:02:53,850
And for this I need to pass in the ID of the post so that I can fetch that and populate the form with

34
00:02:53,850 --> 00:02:55,860
the post that I'm going to fetch.

35
00:02:55,860 --> 00:03:01,680
So async and callback function rec and response.

36
00:03:03,420 --> 00:03:04,130
All right.

37
00:03:04,140 --> 00:03:11,850
The idea is that as soon as the form got rendered, I want to repopulate the post with this specific

38
00:03:11,850 --> 00:03:12,510
ID.

39
00:03:12,900 --> 00:03:19,860
So going to be a try catch and I need to bring in the post model.

40
00:03:19,890 --> 00:03:23,910
Let me save to have the auto import.

41
00:03:26,210 --> 00:03:27,080
Posts.

42
00:03:28,680 --> 00:03:30,810
And I have it down here.

43
00:03:32,740 --> 00:03:38,110
So let's get here and I'm going to be a wait post.

44
00:03:40,970 --> 00:03:44,510
Is equal to a weight post model.

45
00:03:45,750 --> 00:03:51,690
Don't find by id red dot params dot id.

46
00:03:53,320 --> 00:03:53,830
All right.

47
00:03:53,830 --> 00:03:56,560
So we're going to be as concerned instead.

48
00:03:57,390 --> 00:04:10,650
And I'm going to send the template as render and I'll pass in the post, then the update post.

49
00:04:11,510 --> 00:04:14,030
And I'll pass in the post.

50
00:04:14,030 --> 00:04:15,350
That has been fetched.

51
00:04:15,590 --> 00:04:16,130
All right.

52
00:04:16,130 --> 00:04:18,950
And down here, in case we have an error.

53
00:04:19,190 --> 00:04:28,850
I will also render this template and pass in the error here and for the post to here going to be.

54
00:04:29,950 --> 00:04:30,820
Empty.

55
00:04:31,800 --> 00:04:34,210
Okay, so now it will work.

56
00:04:34,240 --> 00:04:41,180
The next step is that we need to render these templates by hitting this root.

57
00:04:41,200 --> 00:04:45,080
So let's get back to the post details.

58
00:04:45,100 --> 00:04:53,920
So let's go to post details, which is this, and let's find the edit icon, which is this.

59
00:04:53,920 --> 00:05:05,800
And I have the pub here and here we are going to use the path as API and version one forward slash post

60
00:05:05,800 --> 00:05:09,940
and for this I want to give it a specific path.

61
00:05:10,210 --> 00:05:16,390
So here I want to give this one a specific name as get that form.

62
00:05:17,320 --> 00:05:18,280
Dash.

63
00:05:19,740 --> 00:05:24,660
Our date and force likes the ID, so let me copy this one.

64
00:05:24,930 --> 00:05:26,250
And back here.

65
00:05:27,150 --> 00:05:35,580
As opposed to march the exact path and then the ID is going to be forward slash, then GCA and the post

66
00:05:35,580 --> 00:05:40,320
can be found as post dot and as core ID.

67
00:05:40,650 --> 00:05:44,130
So this one will be able to render the form.

68
00:05:44,130 --> 00:05:45,600
So save it.

69
00:05:45,600 --> 00:05:49,800
And let's go to the homepage here.

70
00:05:51,500 --> 00:05:53,090
And this post.

71
00:05:54,210 --> 00:05:55,950
And click on that.

72
00:05:57,560 --> 00:06:04,820
You can see that it's been rendered, but I think we are not passing in a properly called error.

73
00:06:05,060 --> 00:06:05,540
All right.

74
00:06:05,540 --> 00:06:09,320
So let's go ahead and pass in into that.

75
00:06:09,590 --> 00:06:11,600
So let's see.

76
00:06:11,600 --> 00:06:12,220
Yeah.

77
00:06:12,230 --> 00:06:16,670
And pass in the error here as the second argument.

78
00:06:17,590 --> 00:06:21,550
So by default, there is no error at this point.

79
00:06:22,130 --> 00:06:22,690
Okay.

80
00:06:22,690 --> 00:06:25,840
So let's go ahead, refresh.

81
00:06:27,600 --> 00:06:36,990
And edit and I have the form and you can see that we have the ID of the post that I want to update.

82
00:06:37,530 --> 00:06:38,010
All right.

83
00:06:38,010 --> 00:06:40,050
So let's continue in the next video.

