1
00:00:00,630 --> 00:00:02,490
Hello our welcome in this special.

2
00:00:02,510 --> 00:00:12,740
We are going to implement some basic error handling that wall display any validation errors on the form.

3
00:00:13,320 --> 00:00:15,590
So this is our form at the moment.

4
00:00:15,780 --> 00:00:23,600
Even though we've got valediction in place if I click save it who'll just return to resod meet and read

5
00:00:23,600 --> 00:00:24,330
a new form.

6
00:00:24,330 --> 00:00:30,570
So he doesn't show any validation error so we don't know was actually going on.

7
00:00:30,600 --> 00:00:38,310
So if we look at the code from our previous and make sure here be here.

8
00:00:38,430 --> 00:00:50,220
The if statement I just want to explain shit on that a little bit inside this create action here.

9
00:00:50,340 --> 00:00:58,830
Notice here I've used the render rather than read direct surrender re renders a new form one rendered

10
00:00:58,830 --> 00:00:59,610
and redirect.

11
00:00:59,610 --> 00:01:05,700
I just wanna explain the difference between the render and the redirect.

12
00:01:05,820 --> 00:01:16,940
So bisley what happens is that in its sybase Create action the render by using the render centre redirect.

13
00:01:17,160 --> 00:01:21,400
When we see the returns when what this is says.

14
00:01:21,420 --> 00:01:25,250
If this say is force who does quantitation use force.

15
00:01:25,260 --> 00:01:35,580
When you tried to say The form does if the condition is force the render Mento is used so that the post

16
00:01:35,880 --> 00:01:38,840
at the pools a variable.

17
00:01:38,850 --> 00:01:47,860
This here the post variable object is passed back to the new template when it is rendered.

18
00:01:47,940 --> 00:01:50,060
Well it does so.

19
00:01:50,070 --> 00:01:59,810
This rendering is done within the same request as the form submission whereas with the redirect it will

20
00:01:59,880 --> 00:02:08,300
tell the browser to reissue another request so rendering doesn't issue another request or redirect or

21
00:02:08,310 --> 00:02:10,900
go back to the browser to reshoot.

22
00:02:11,160 --> 00:02:15,710
And that I request that's the key difference between the redirect and the render.

23
00:02:15,720 --> 00:02:18,750
Just wanted to point that out.

24
00:02:18,750 --> 00:02:23,660
Now let's go back to our for the new form template.

25
00:02:23,880 --> 00:02:30,780
That's where we're going to implement the error or handly So we've been our template and will likely

26
00:02:30,780 --> 00:02:37,300
confuse and all good to new so this is where we going to implement it.

27
00:02:37,380 --> 00:02:38,240
One would need to.

28
00:02:38,250 --> 00:02:45,080
I'm just going to come down here load a bit.

29
00:02:45,090 --> 00:02:46,910
A trillion are implementing it on.

30
00:02:46,940 --> 00:02:48,630
Here are just tab that back.

31
00:02:48,690 --> 00:02:51,460
I'm just going to here.

32
00:02:51,500 --> 00:02:54,630
I'm just going to tap down and implement it.

33
00:02:54,630 --> 00:03:01,620
I've already written it out just to save time going to pay seeing here it be available for you on the

34
00:03:01,620 --> 00:03:05,450
resource download if you want to just copy and paste here as well.

35
00:03:05,490 --> 00:03:11,900
If you don't want to write in so this is what this is there are and and this is what pasiphae was up

36
00:03:12,000 --> 00:03:12,810
they said in.

37
00:03:12,840 --> 00:03:16,280
I'll explain to you what's going on.

38
00:03:16,310 --> 00:03:18,980
I'm in a place in here.

39
00:03:20,600 --> 00:03:23,720
K make sure keep a big gap.

40
00:03:24,280 --> 00:03:26,790
Okay and I'll just say that.

41
00:03:28,730 --> 00:03:38,750
So what this statement is saying is that if there's any errors durene the post on the form we want to

42
00:03:38,750 --> 00:03:43,690
look through the error messages and display this message here.

43
00:03:43,700 --> 00:03:52,120
This is in Bootstrap class so he to display the alert and also highlight the validation what error message.

44
00:03:52,280 --> 00:03:59,960
For example if you fail to enter the minimum amount of character for the title it'll alert that and

45
00:03:59,960 --> 00:04:05,560
display that in red which is colour like a book's trump card class.

46
00:04:05,600 --> 00:04:07,520
That's what that is.

47
00:04:07,520 --> 00:04:16,600
So next him we need to do is go to our control up and the references to this variable here.

48
00:04:16,700 --> 00:04:20,570
So let's go to the controller here and go to poor squall.

49
00:04:20,580 --> 00:04:21,220
True.

50
00:04:21,470 --> 00:04:23,380
So we'll go to the new section here.

51
00:04:23,390 --> 00:04:28,000
This is where we'll add a reference to that variable.

52
00:04:28,070 --> 00:04:31,000
So we're just going to come here to add a new at.

53
00:04:31,040 --> 00:04:39,730
And here I'm just going to see that to define the incidence of the terrible paused to one set that equals

54
00:04:39,800 --> 00:04:44,360
to the post which is the post model.

55
00:04:45,170 --> 00:04:49,270
Does New York say that.

56
00:04:50,750 --> 00:04:55,060
Kate now we should be able to test the form likely.

57
00:04:55,220 --> 00:05:03,500
Just refresh that and click on create new posts and try to see that a go.

58
00:05:03,620 --> 00:05:06,170
So the error handling is working is this here.

59
00:05:06,180 --> 00:05:08,560
Title can't be blank.

60
00:05:08,600 --> 00:05:12,200
Title is too short mean a mom is four characters.

61
00:05:12,500 --> 00:05:17,930
So the Herro handling is working great if you get the same response well done.

62
00:05:17,930 --> 00:05:22,960
If you don't you get it Aeros let me know we'll try and sort it out together.

63
00:05:23,240 --> 00:05:25,000
That's it for this Late Show.

64
00:05:25,010 --> 00:05:28,550
Many thanks for watching and bye for now.
