Hello our welcome in this special.
We are going to implement some basic error handling that wall display any validation errors on the form.
So this is our form at the moment.
Even though we've got valediction in place if I click save it who'll just return to resod meet and read
a new form.
So he doesn't show any validation error so we don't know was actually going on.
So if we look at the code from our previous and make sure here be here.
The if statement I just want to explain shit on that a little bit inside this create action here.
Notice here I've used the render rather than read direct surrender re renders a new form one rendered
and redirect.
I just wanna explain the difference between the render and the redirect.
So bisley what happens is that in its sybase Create action the render by using the render centre redirect.
When we see the returns when what this is says.
If this say is force who does quantitation use force.
When you tried to say The form does if the condition is force the render Mento is used so that the post
at the pools a variable.
This here the post variable object is passed back to the new template when it is rendered.
Well it does so.
This rendering is done within the same request as the form submission whereas with the redirect it will
tell the browser to reissue another request so rendering doesn't issue another request or redirect or
go back to the browser to reshoot.
And that I request that's the key difference between the redirect and the render.
Just wanted to point that out.
Now let's go back to our for the new form template.
That's where we're going to implement the error or handly So we've been our template and will likely
confuse and all good to new so this is where we going to implement it.
One would need to.
I'm just going to come down here load a bit.
A trillion are implementing it on.
Here are just tab that back.
I'm just going to here.
I'm just going to tap down and implement it.
I've already written it out just to save time going to pay seeing here it be available for you on the
resource download if you want to just copy and paste here as well.
If you don't want to write in so this is what this is there are and and this is what pasiphae was up
they said in.
I'll explain to you what's going on.
I'm in a place in here.
K make sure keep a big gap.
Okay and I'll just say that.
So what this statement is saying is that if there's any errors durene the post on the form we want to
look through the error messages and display this message here.
This is in Bootstrap class so he to display the alert and also highlight the validation what error message.
For example if you fail to enter the minimum amount of character for the title it'll alert that and
display that in red which is colour like a book's trump card class.
That's what that is.
So next him we need to do is go to our control up and the references to this variable here.
So let's go to the controller here and go to poor squall.
True.
So we'll go to the new section here.
This is where we'll add a reference to that variable.
So we're just going to come here to add a new at.
And here I'm just going to see that to define the incidence of the terrible paused to one set that equals
to the post which is the post model.
Does New York say that.
Kate now we should be able to test the form likely.
Just refresh that and click on create new posts and try to see that a go.
So the error handling is working is this here.
Title can't be blank.
Title is too short mean a mom is four characters.
So the Herro handling is working great if you get the same response well done.
If you don't you get it Aeros let me know we'll try and sort it out together.
That's it for this Late Show.
Many thanks for watching and bye for now.