Hello and welcome.
In this life sure we are going to add the action that will enable or create comments for our books.
So we're going to do this inside be comments controller.
So if you just navigate to where your controllers are which is uncanny upstair acri controller and then
comments.
So this is where we are going to create our action.
So the first action I'm going to create here just kind of sat down.
I'm going to define a create method so you do d.f. and bend the word create.
And then end it.
So before I add anything I want to create a private method that only be accessible from the class.
So to define a private metate he just type in the word private space and then followed by deaf and then
comment thus the name am given to it on the score power Rams.
Just like we did with the post quantrell.
I'm going to just add some values here so I'm going to see Pat ramps.
Don't require So these are the fields that will be required for the comments form.
And will grab that empathises and add a quill on then typing the word comment.
I'm good as both at what we are going to allow.
So I'm going to pair meet.
Impaired folded depending on what you specified when you created the model.
For me I specified just a name.
So whatever a name you specify it is what you'd need to enter comma.
Space call on an also specified is a body.
And then are yours.
And Nat.
Okay so now they're back in place.
I can go inside the create methods and just had some various books.
I'm going to add the post variable.
Will look post equal to the submitted post model.
You can identify with a capital P.
So a B post.
Find.
And empathises.
I'm going to add para ohms.
Inside them going to add.
The Post.
So what.
The value it would take is the post I d.
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
add a comment variable and do that.
Comment.
And will a set back two equals two.
The posed variable.
Okay.
DOT.
Comments.
Dot Creed's.
And in parentheses we're going to pass in this here that we create so begin to comment on the score
prompts that we pass him this in their necks and we need to do.
We need to redirect.
Once a comment has been created we want to redirect the user somewhere else or would typee redirect.
On the score to specify where we direct in them to so with their it in them to the post on the score
PAFF.
And inside the pen this is.
We pass in the post variable.
Okay that should do it.
Save that bisch LEARN Let's do some testing before we can test.
We need to commence to show one's comments someone's left a comment.
We want the comments to show.
So to do that we need to go to D sure V you came within the post.
So this is a post on the views post when they click on the show for you.
And we need to add somewhere that would display the comments or.
So what I'm going to do are just on the base a chart tag here.
I'm going to just add add it so I've added decode here that will enable the comments to show in the
sure.
P So this is what I have added on.
So basically here we have the post variable here.
Notice after the percent here there is no it was to a because I'm not output in any form.
But here I have implemented the loop so what.
This should happen.
It will loop through each comment and inside between the piping.
Pass in the comment and wrapped it round the div here so it will have a D.
I've given the div a class of.
Well this is a boson trap class.
And here this.
Here is the name I've said within the model so depending what yours this fields's call username or whatever
you should add that there are more that will do when the comment is made.
It will make whoever has left the comment to give the name it Balde name to make it.
That's what the strong tag does.
And then we've got the comment here.
OK we've got this here.
The percent here which is the quote with said that that's going to put something.
The Bears equals the next so the percent Emens use.
But you are expecting an output.
See.
This will output the content of the body.
And here's what we expect in an output tool.
I'll put the name of the person live in the comment and wrap this here in a div here and then here we
are ending what we started here.
The percent here and this is the end of the list saved that.
And we should be able to add a comment.
Let's go back to our blog um as can a refresh just to make sure there's no errors.
Let's test this out.
I'm going to add a comment name our just saying
blue line
learning.
Body o saying.
Great post.
Quick create.
And if everything works out.
Oh excellent is working.
So there you go.
So that's blue lime learnin.
Who's left the comment.
And this is what they've said.
Great post fantastic.
So are we now we're able to add comment at the moment.
We can't delete comment because we want to be a book.
We want to be able to delete comments as well so we will implement that in subsequent lectures from
hell.
Thanks for watching and bye for now.