Hello and welcome.
In this lecture we are going to generate our first controller.
The controller basically is used to receive specific request for the application or the information
or the request may be collected by a controller and a controller can have one or several actions on
method method.
Basically it's no different actions that the controller takes in some programming language.
They called me third in Ruby on Rails.
It's referred to as action.
So we've still got our application running.
I'm going to leave it run in here so that as we build the projet there any error messages we can see
them displayed.
One good thing about having the server running any changes you make as you're building the application
it automatically reflects.
You don't really need to refresh the page so if this page disappears or if it comes up in a way that
you are not expected any of it throws up errors that means you've obviously done something wrong.
So we'll leave it running.
Are we also need to leave the server console running this Contra's that saal minimize that and open
another console so to do that the quick way to do that you go to where your program is.
This is mine I just right click and go get back here that saves me from type in the path.
So I've now got a new command line and it links me directly to my project.
So this is where I'm going to create or generate he new controller.
So I am on a Windows based computer.
I'm going to run this true the been there increase.
I'm going to do being slash.
Then the command you need to generate a control line is called.
Type in rails.
Well unless space you can I doubt typing generate any fool or just type in G space and then you meet
to specify what you generate in this case control us.
So you type in quantrell.
Space followed by the name of the controller.
I am going to call mime pulse.
Yeah.
And then as.
Why are you defining your control.
You can also find a method or an action.
So I'm going to do a space and define an action as well.
You don't have to define an action at this stage.
You can add it on later.
Once the control has been created by I'm going to add one I'm going to make it really be action as in
lower case and one and two index.
So that would be my action for that control and my first action I will have several actions for this
control I later suppress enter and choose to go ahead and generate the controller.
So there you go is generator.
The controller has generated a few files with it.
So tell us the cinerator the quantrell like India's directory app quantrell Allows post underscore that
it's got a dot RB extension.
These are they wrote most control our we have a route a road bisley here's the path they take when it
requests comes true.
All the files is generated.
The most important ones here.
Up quantrell allows that one and this far here the index for you.
So this is a view that actually displays the data that is presented by the controller.
Notice here the view here as quote indexed or hit him into to b b terms for embedded Ruby so is embedded
Ruby tags inside his team.
Kind of like his team Ruby style.
So that's us.
What will this play the information for the user to see.
So let's take a look at a couple of the files in our text editor.
So I'll put my text tone and open this Derek record app.
This therapy is quite important.
It contains all the MVC structure also contains the model that you and the controller.
So expand the controller tab.
And this is the control over just created.
Post this quote this here application controller.
This is the main control as well any quantrell you create will extend this controller a case for this
as the main class controller.
Anything else you give will extend this wi-fi.
Well not this post on the SQL control and now would just create it.
He should have his reference to this so let me click on that as you can see.
Got a reference for the application controller which is this controller here.
So any other controller will preference this.
You can easily is usually to find this less than sign.
All right because we we created the controller.
We also specified We wanted the action and action to the action.
This is how you define an action and action basically is also referred to as a method not a programming
language so you do d.f. followed by the name of the action so index in this will be our home page.
When the application is visited when you launch it he should reference to this index page.
He also creates a corresponding view.
So if I come down he expanded Hughes option just to see if called up look on the post.
Remember when we created the post he also created an index you expand that and you can see if this is
the embedded Ruby file.
So this is basically what he looks like.
It's an embedded Ruby file.
Weekend does.
You can leave this or you can see here is the name of the controller and this is a name of the action
so you can get rid of the content that candidly.
I'm just going to change the message here.
Get rid of that.
I'm going to just typing in.
Hello world.
And is get rid of that and say this.
To save or if I open up the you can see here now.
This is the home page.
What I wanted to do.
If you look at this link here says local horse 3 points then I want to display this message rather than
that so to do that we are going to have to make modification to the root.
So in the next lecture will cover how to do that would change the homepage to reflect this message here.
So that's it for this lecture.
Thanks for watching.
Bye for now.