1 00:00:00,510 --> 00:00:01,520 Hello and welcome. 2 00:00:01,530 --> 00:00:06,720 In this lecture we are going to generate our first controller. 3 00:00:06,880 --> 00:00:16,020 The controller basically is used to receive specific request for the application or the information 4 00:00:16,540 --> 00:00:27,870 or the request may be collected by a controller and a controller can have one or several actions on 5 00:00:27,900 --> 00:00:29,730 method method. 6 00:00:29,730 --> 00:00:36,230 Basically it's no different actions that the controller takes in some programming language. 7 00:00:36,870 --> 00:00:39,610 They called me third in Ruby on Rails. 8 00:00:39,720 --> 00:00:42,840 It's referred to as action. 9 00:00:42,840 --> 00:00:45,650 So we've still got our application running. 10 00:00:45,670 --> 00:00:52,830 I'm going to leave it run in here so that as we build the projet there any error messages we can see 11 00:00:52,830 --> 00:00:54,380 them displayed. 12 00:00:54,390 --> 00:00:59,100 One good thing about having the server running any changes you make as you're building the application 13 00:00:59,120 --> 00:01:01,010 it automatically reflects. 14 00:01:01,110 --> 00:01:07,920 You don't really need to refresh the page so if this page disappears or if it comes up in a way that 15 00:01:07,920 --> 00:01:12,900 you are not expected any of it throws up errors that means you've obviously done something wrong. 16 00:01:12,900 --> 00:01:14,640 So we'll leave it running. 17 00:01:14,750 --> 00:01:22,800 Are we also need to leave the server console running this Contra's that saal minimize that and open 18 00:01:22,800 --> 00:01:29,850 another console so to do that the quick way to do that you go to where your program is. 19 00:01:29,910 --> 00:01:39,150 This is mine I just right click and go get back here that saves me from type in the path. 20 00:01:39,480 --> 00:01:46,230 So I've now got a new command line and it links me directly to my project. 21 00:01:46,230 --> 00:01:51,340 So this is where I'm going to create or generate he new controller. 22 00:01:51,530 --> 00:01:54,000 So I am on a Windows based computer. 23 00:01:54,000 --> 00:01:56,160 I'm going to run this true the been there increase. 24 00:01:56,160 --> 00:01:59,510 I'm going to do being slash. 25 00:01:59,610 --> 00:02:03,690 Then the command you need to generate a control line is called. 26 00:02:03,700 --> 00:02:05,270 Type in rails. 27 00:02:06,520 --> 00:02:15,600 Well unless space you can I doubt typing generate any fool or just type in G space and then you meet 28 00:02:15,600 --> 00:02:18,950 to specify what you generate in this case control us. 29 00:02:18,960 --> 00:02:21,150 So you type in quantrell. 30 00:02:22,760 --> 00:02:25,540 Space followed by the name of the controller. 31 00:02:25,550 --> 00:02:28,040 I am going to call mime pulse. 32 00:02:32,020 --> 00:02:32,580 Yeah. 33 00:02:33,510 --> 00:02:34,770 And then as. 34 00:02:34,800 --> 00:02:37,570 Why are you defining your control. 35 00:02:37,590 --> 00:02:41,930 You can also find a method or an action. 36 00:02:42,000 --> 00:02:45,270 So I'm going to do a space and define an action as well. 37 00:02:45,270 --> 00:02:47,840 You don't have to define an action at this stage. 38 00:02:47,850 --> 00:02:49,620 You can add it on later. 39 00:02:49,930 --> 00:02:56,760 Once the control has been created by I'm going to add one I'm going to make it really be action as in 40 00:02:56,770 --> 00:02:59,340 lower case and one and two index. 41 00:02:59,610 --> 00:03:05,550 So that would be my action for that control and my first action I will have several actions for this 42 00:03:05,550 --> 00:03:13,920 control I later suppress enter and choose to go ahead and generate the controller. 43 00:03:14,670 --> 00:03:16,170 So there you go is generator. 44 00:03:16,180 --> 00:03:19,670 The controller has generated a few files with it. 45 00:03:19,860 --> 00:03:26,790 So tell us the cinerator the quantrell like India's directory app quantrell Allows post underscore that 46 00:03:28,260 --> 00:03:31,330 it's got a dot RB extension. 47 00:03:31,400 --> 00:03:38,100 These are they wrote most control our we have a route a road bisley here's the path they take when it 48 00:03:38,100 --> 00:03:40,720 requests comes true. 49 00:03:40,920 --> 00:03:43,830 All the files is generated. 50 00:03:43,830 --> 00:03:45,930 The most important ones here. 51 00:03:46,050 --> 00:03:52,500 Up quantrell allows that one and this far here the index for you. 52 00:03:52,510 --> 00:04:00,250 So this is a view that actually displays the data that is presented by the controller. 53 00:04:00,900 --> 00:04:10,860 Notice here the view here as quote indexed or hit him into to b b terms for embedded Ruby so is embedded 54 00:04:10,860 --> 00:04:13,420 Ruby tags inside his team. 55 00:04:13,560 --> 00:04:16,030 Kind of like his team Ruby style. 56 00:04:16,240 --> 00:04:17,940 So that's us. 57 00:04:18,000 --> 00:04:22,930 What will this play the information for the user to see. 58 00:04:23,470 --> 00:04:28,120 So let's take a look at a couple of the files in our text editor. 59 00:04:28,450 --> 00:04:32,170 So I'll put my text tone and open this Derek record app. 60 00:04:32,370 --> 00:04:34,650 This therapy is quite important. 61 00:04:34,650 --> 00:04:41,190 It contains all the MVC structure also contains the model that you and the controller. 62 00:04:41,490 --> 00:04:44,160 So expand the controller tab. 63 00:04:44,300 --> 00:04:46,610 And this is the control over just created. 64 00:04:46,640 --> 00:04:50,080 Post this quote this here application controller. 65 00:04:50,310 --> 00:04:57,450 This is the main control as well any quantrell you create will extend this controller a case for this 66 00:04:57,450 --> 00:04:58,880 as the main class controller. 67 00:04:58,920 --> 00:05:01,940 Anything else you give will extend this wi-fi. 68 00:05:02,030 --> 00:05:05,680 Well not this post on the SQL control and now would just create it. 69 00:05:05,680 --> 00:05:10,770 He should have his reference to this so let me click on that as you can see. 70 00:05:10,870 --> 00:05:14,990 Got a reference for the application controller which is this controller here. 71 00:05:15,030 --> 00:05:18,250 So any other controller will preference this. 72 00:05:18,330 --> 00:05:22,610 You can easily is usually to find this less than sign. 73 00:05:22,920 --> 00:05:25,970 All right because we we created the controller. 74 00:05:25,980 --> 00:05:30,900 We also specified We wanted the action and action to the action. 75 00:05:30,900 --> 00:05:36,510 This is how you define an action and action basically is also referred to as a method not a programming 76 00:05:36,510 --> 00:05:45,780 language so you do d.f. followed by the name of the action so index in this will be our home page. 77 00:05:45,960 --> 00:05:54,240 When the application is visited when you launch it he should reference to this index page. 78 00:05:54,250 --> 00:05:57,800 He also creates a corresponding view. 79 00:05:58,020 --> 00:06:06,060 So if I come down he expanded Hughes option just to see if called up look on the post. 80 00:06:06,210 --> 00:06:12,540 Remember when we created the post he also created an index you expand that and you can see if this is 81 00:06:12,540 --> 00:06:14,850 the embedded Ruby file. 82 00:06:15,000 --> 00:06:18,190 So this is basically what he looks like. 83 00:06:18,270 --> 00:06:20,440 It's an embedded Ruby file. 84 00:06:20,460 --> 00:06:21,330 Weekend does. 85 00:06:21,360 --> 00:06:29,220 You can leave this or you can see here is the name of the controller and this is a name of the action 86 00:06:30,660 --> 00:06:33,450 so you can get rid of the content that candidly. 87 00:06:33,460 --> 00:06:35,240 I'm just going to change the message here. 88 00:06:35,240 --> 00:06:37,110 Get rid of that. 89 00:06:37,170 --> 00:06:40,900 I'm going to just typing in. 90 00:06:42,000 --> 00:06:43,740 Hello world. 91 00:06:49,340 --> 00:06:53,850 And is get rid of that and say this. 92 00:06:55,790 --> 00:07:00,570 To save or if I open up the you can see here now. 93 00:07:00,590 --> 00:07:01,850 This is the home page. 94 00:07:02,060 --> 00:07:03,440 What I wanted to do. 95 00:07:03,440 --> 00:07:10,220 If you look at this link here says local horse 3 points then I want to display this message rather than 96 00:07:10,230 --> 00:07:15,170 that so to do that we are going to have to make modification to the root. 97 00:07:15,410 --> 00:07:22,480 So in the next lecture will cover how to do that would change the homepage to reflect this message here. 98 00:07:22,760 --> 00:07:24,660 So that's it for this lecture. 99 00:07:24,710 --> 00:07:26,150 Thanks for watching. 100 00:07:26,150 --> 00:07:27,040 Bye for now.