Hello and welcome in this chair.
We are going to try and see that are in B control.
In a previous Lakeshore we created a model so we're going to do how it is meant to create action to
reflect the new model that was created.
So make sure you are him the post on this call control file and you can see this is the create action.
We just need to our members since we've created a model at the moment what is doing is just rendering
whether it's posted on the form is meant the net rendering it as an object like this.
So we want it to render to the database via that model.
So I'm just going to comment that out.
You can delete it if you wish to do so but come in today for now.
We just had some.
I'm going to start by adding it variable and variable.
I'm going to add I'm going to call it pause.
So this is the same board to had variable in Ruby.
So you just look at full of by paused in law case.
I'm going to set that to equal to OP Keith Post dot new.
N n t.
Parent disease inside the person who sees half passing nipa trumps an ad and every column and then passing
the post object.
So what I've done here.
That line of code basically any time you create a model you have to initialize the model you uninitialised.
You've seen its attributes.
So here be the attributes here are automatically mapped to the respective database columns so these
two columns in a database which is title and the body and we represent in that we're the paramus and
then the post that will give us the values of the columns in the database table.
Another thing we can do is add on another variable that will be responsible for saving the module in
the database.
So we're just going to add that variable now.
So we do at the time pick the word Post dot see.
So this is what will save the data into the database using the model and then once it's been safe you
want to be able to redirect it back somewhere so you do redirect
on the score to 1 to redirect it back to the post variable at ports.
I just want to create a space between that with the one hole.
Okay.
So read did underscore to at this post variable.
So this read death rate here is going to redirect the user to the show action.
We've not defined the show action yet but that's where it will redirect the user to something I want
to point out here.
Notice here we set this up pause variable two equals to pause new.
And the reason we've got the P in upper case everything is capitalize is that it is referred to as a
class.
It is a class.
That's why it is capitalized.
So we are actually referring to V post that defined n bit cap models article Dort are B.
All right.
So we could post on this yeah to the HARP on the score models.
If you go to aps and then go to modules and post B were referring to this class.
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.
Thus the fear of the post it is referring to.
So let's see and try and submit our form and see what happens.
So we refresh this week in gowe form back.
So this is our form.
So let me just try and post something and I do expect to get an error.
Click save and see what happens.
So you can see we are getting an error here.
Let me just expand the Thera.
So is saying active model for the entire trip is the reason we're getting this error is that we've not
had fully defined any special fields full of post so we don't live in peoples minds.
We must define the feel we dont want people to just post anything they like.
So if the security issues that we need to address so Real's has several security features that helps
you right seek your application so when you are run into one of those features like we can see here
on the screen may actually called strong prime it is what that does it out to be.
He requires all reals is telling us to tell it exactly what parameters we are going to allow in to harm
a controller actions so we need to tell it what we have to do is create a private method or action that
can only be accessed from this class so when a method is made private It cannot be accessed outside
the class so you need to create a private metal.
You type in the word private.
Okay and then here then you then define do a diff to define.
Then I'm going to call it post on the score.
Programs or the parameters.
And here I'm going to specifying some values and when I say firearms do not require so I am setting
the feels that the form will require and then empathises is on typing post and then here do not permit
which means these other fields are permitted or fields or columns permitted.
And then you do a call on the title we want the title comma space and there we also want the body so
to call on unban.
But the.
And we need to end the methot typing end as to end it.
So now that we've defined the we defined it created this private method here and we've got this action
here called programs we have to amend the variable here to reflect what we have set here and the way
we do that where we've got Post he to pause and cool down new.
So we're going to keep passing.
We're going to change this because we've got we're going to get the value from here.
So we changed that from paramus Depp to post
on the score.
Paramount's
okay because we've already defined it here so we're picking the values from here and amended it there.
So now if we save and then go back and refresh half form or fully that we should now be able to save
data to the controller.
So led to a test and got to turn to code test and anybody else has called a textureless to save post.
Hopefully we should not get the error.
Actually yes we have gotten there and it's a valid error.
The reason we have got the error is is clearly obvious.
We have not created the shule action inside the post quantrill So this is a post controller.
He can see there's no issue here even.
We got his save here we've told it to read there it took pause which is this show we haven't defined
this show here.
That's why we get in error so I'm going to end this lecture here in the next lecture.
Will had the Schul action to the post controller.
Many thanks for watching by.