1 00:00:00,000 --> 00:00:03,968 >> [MUSIC PLAYING] 2 00:00:03,968 --> 00:00:10,744 3 00:00:10,744 --> 00:00:14,040 >> STEPHEN TURBAN: So I'm Stephen Turban. 4 00:00:14,040 --> 00:00:16,990 Over on the side here, maybe we can get some people to dive in. 5 00:00:16,990 --> 00:00:20,150 6 00:00:20,150 --> 00:00:23,854 We have Gabriel and Zack. 7 00:00:23,854 --> 00:00:26,270 So for a brief roadmap on what this is going to look like, 8 00:00:26,270 --> 00:00:31,580 I'm going to be doing some extremely high-level look at what MVC is. 9 00:00:31,580 --> 00:00:32,285 Gabe? 10 00:00:32,285 --> 00:00:35,080 >> GABRIEL GUIMARAES: I'm going to talk about Ruby and a little bit 11 00:00:35,080 --> 00:00:39,100 how Rails works and how it can help you build web applications. 12 00:00:39,100 --> 00:00:42,070 >> ZACK CHAUVIN: And I'm going to show you a specific example of how 13 00:00:42,070 --> 00:00:45,112 to use Rails to build a super awesome app. 14 00:00:45,112 --> 00:00:46,112 STEPHEN TURBAN: Awesome. 15 00:00:46,112 --> 00:00:46,350 Sweet. 16 00:00:46,350 --> 00:00:46,850 All right. 17 00:00:46,850 --> 00:00:49,510 So let's talk about MVC. 18 00:00:49,510 --> 00:00:54,970 So let's go to the next slide, which I will do by pressing this button. 19 00:00:54,970 --> 00:01:12,640 And let's go to the next-- development, I like to think about going to CVS, 20 00:01:12,640 --> 00:01:17,240 because CVS is a store and also has a V in the center. 21 00:01:17,240 --> 00:01:21,460 >> And so let's imagine to a store. 22 00:01:21,460 --> 00:01:25,380 And let's make this store sell only one thing. 23 00:01:25,380 --> 00:01:31,380 So we're going to have this store only sell these red cups. 24 00:01:31,380 --> 00:01:40,410 And imagine you walk in, and you go to the front of the store, and person. 25 00:01:40,410 --> 00:01:43,440 And his name is Vince. 26 00:01:43,440 --> 00:01:48,370 >> And Vince waves hello at you, says hi. 27 00:01:48,370 --> 00:01:50,860 And you notice one thing about Vince. 28 00:01:50,860 --> 00:01:56,880 So whenever we think about Vince, we have to think about two key adjectives. 29 00:01:56,880 --> 00:02:00,600 Vince is beautiful, but he's stupid. 30 00:02:00,600 --> 00:02:01,320 OK. 31 00:02:01,320 --> 00:02:06,810 So you know, no fault of his own, unfortunately, he's beautiful. 32 00:02:06,810 --> 00:02:08,009 He is our view. 33 00:02:08,009 --> 00:02:10,539 So our first cast member is there. 34 00:02:10,539 --> 00:02:12,340 Keep that in mind. 35 00:02:12,340 --> 00:02:17,230 >> Now, you ask Vince, you go, hey Vince. 36 00:02:17,230 --> 00:02:18,110 I'm a customer. 37 00:02:18,110 --> 00:02:19,130 He says hi. 38 00:02:19,130 --> 00:02:23,610 I really want one of your red cups. 39 00:02:23,610 --> 00:02:24,760 And what does Vince say? 40 00:02:24,760 --> 00:02:26,510 Does anyone have any idea what Vince says? 41 00:02:26,510 --> 00:02:30,340 42 00:02:30,340 --> 00:02:31,452 I'm going to cold call. 43 00:02:31,452 --> 00:02:32,660 What do you think Vince says? 44 00:02:32,660 --> 00:02:36,139 >> AUDIENCE: He says, I can show you where it is, but I can't give you one. 45 00:02:36,139 --> 00:02:41,330 >> STEPHEN TURBAN: He says, I can show you where it is, but I can't give you one. 46 00:02:41,330 --> 00:02:42,295 Even worse. 47 00:02:42,295 --> 00:02:44,420 Anyone else have another idea what Vince might say? 48 00:02:44,420 --> 00:02:46,957 >> AUDIENCE: He has to go check if they have any red cups. 49 00:02:46,957 --> 00:02:49,290 STEPHEN TURBAN: Vince doesn't even know he has to check. 50 00:02:49,290 --> 00:02:50,070 Anything else? 51 00:02:50,070 --> 00:02:52,360 So you said, has to check if he has red cups. 52 00:02:52,360 --> 00:02:52,895 Go ahead. 53 00:02:52,895 --> 00:02:54,020 AUDIENCE: What's a red cup? 54 00:02:54,020 --> 00:02:56,072 STEPHEN TURBAN: What's a red cup? 55 00:02:56,072 --> 00:02:58,090 What's a red cup? 56 00:02:58,090 --> 00:02:59,410 Vince is confused. 57 00:02:59,410 --> 00:03:05,141 So Vince is going to talk to our next cast member, Carl. 58 00:03:05,141 --> 00:03:10,252 And when we think about Carl, we gotta think about two big adjectives-- 59 00:03:10,252 --> 00:03:15,110 he's controlling, but he's incapable. 60 00:03:15,110 --> 00:03:17,840 >> So Vince goes-- he goes, what is a red cup? 61 00:03:17,840 --> 00:03:19,800 I don't know what a red cup is. 62 00:03:19,800 --> 00:03:23,080 He turns around, and he asks Carl. 63 00:03:23,080 --> 00:03:28,890 He says, Carl, someone asked for a red cup. 64 00:03:28,890 --> 00:03:30,722 Can you do that? 65 00:03:30,722 --> 00:03:31,680 And what does Carl say? 66 00:03:31,680 --> 00:03:32,513 Let's figure it out. 67 00:03:32,513 --> 00:03:34,330 Does anybody have any idea what Carl says? 68 00:03:34,330 --> 00:03:37,260 And I'll just repeat it back to you. 69 00:03:37,260 --> 00:03:39,280 I saw a hand movement. 70 00:03:39,280 --> 00:03:41,760 >> AUDIENCE: He tells someone else to get the red cups. 71 00:03:41,760 --> 00:03:44,430 >> STEPHEN TURBAN: He tells someone else to get the red cup. 72 00:03:44,430 --> 00:03:46,270 Exactly. 73 00:03:46,270 --> 00:03:49,010 And do we have an idea who that person might be? 74 00:03:49,010 --> 00:03:52,590 75 00:03:52,590 --> 00:03:53,090 It's a hint. 76 00:03:53,090 --> 00:03:56,960 It's going to start with an M. Mob? 77 00:03:56,960 --> 00:04:00,225 >> AUDIENCE: Model. 78 00:04:00,225 --> 00:04:02,720 >> STEPHEN TURBAN: The model, yes. 79 00:04:02,720 --> 00:04:06,920 His name is not Model, unfortunately, because that's a silly name. 80 00:04:06,920 --> 00:04:09,310 We have Mitt. 81 00:04:09,310 --> 00:04:12,970 And when we think about Mitt-- no, this is not a picture of Zack. 82 00:04:12,970 --> 00:04:15,590 83 00:04:15,590 --> 00:04:21,759 We have to think of two key adjectives with Mitt. 84 00:04:21,759 --> 00:04:25,040 He's capable, but he's submissive. 85 00:04:25,040 --> 00:04:29,950 So Mitt knows what he has to do, but he really can't do anything. 86 00:04:29,950 --> 00:04:32,340 Or he really can't decide on his own. 87 00:04:32,340 --> 00:04:33,256 >> So we have Carl. 88 00:04:33,256 --> 00:04:34,705 Carl shouts at Mitt. 89 00:04:34,705 --> 00:04:39,990 And he says, hey Mitt, we need red cups. 90 00:04:39,990 --> 00:04:46,410 And Mitt goes to his red cup depository. 91 00:04:46,410 --> 00:04:48,960 He grabs a cup, and he gives it back. 92 00:04:48,960 --> 00:04:51,360 Does anybody have any idea what happens then? 93 00:04:51,360 --> 00:04:54,070 94 00:04:54,070 --> 00:04:55,120 Gives the cup. 95 00:04:55,120 --> 00:05:01,740 So far Mitt has gone to his red cup repository, taken it out, 96 00:05:01,740 --> 00:05:03,550 checked it off, said, I took one red cup. 97 00:05:03,550 --> 00:05:06,717 And he's giving it to Carl. 98 00:05:06,717 --> 00:05:07,550 Do you have an idea? 99 00:05:07,550 --> 00:05:08,980 What do you think Carl does? 100 00:05:08,980 --> 00:05:10,926 >> AUDIENCE: Carl gives it to Vince. 101 00:05:10,926 --> 00:05:13,550 >> STEPHEN TURBAN: Carl gives it to Vince. 102 00:05:13,550 --> 00:05:14,165 Vince. 103 00:05:14,165 --> 00:05:15,999 >> AUDIENCE: And Vince shows it to [INAUDIBLE]. 104 00:05:15,999 --> 00:05:16,998 STEPHEN TURBAN: Exactly. 105 00:05:16,998 --> 00:05:18,080 So that's exactly it. 106 00:05:18,080 --> 00:05:21,040 So Vince takes the cup, doesn't even know what it is, 107 00:05:21,040 --> 00:05:23,840 but he shows it to the user. 108 00:05:23,840 --> 00:05:27,140 So let's try to recreate this really briefly. 109 00:05:27,140 --> 00:05:31,380 And we're gonna need three silent volunteers, 110 00:05:31,380 --> 00:05:35,260 as you guys are not going to be able to speak. 111 00:05:35,260 --> 00:05:36,470 So could I grab three? 112 00:05:36,470 --> 00:05:37,040 OK. 113 00:05:37,040 --> 00:05:38,248 And who would you like to be? 114 00:05:38,248 --> 00:05:42,310 115 00:05:42,310 --> 00:05:43,750 >> AUDIENCE: I'll be Vince. 116 00:05:43,750 --> 00:05:44,960 >> STEPHEN TURBAN: Vince, OK. 117 00:05:44,960 --> 00:05:46,190 Beautiful but stupid. 118 00:05:46,190 --> 00:05:47,510 Great. 119 00:05:47,510 --> 00:05:48,570 Anyone else? 120 00:05:48,570 --> 00:05:53,520 We're looking for a capable but submissive. 121 00:05:53,520 --> 00:05:55,760 Anybody else want to be capable? 122 00:05:55,760 --> 00:05:56,944 >> AUDIENCE: I could be Carl. 123 00:05:56,944 --> 00:05:57,860 STEPHEN TURBAN: Sweet. 124 00:05:57,860 --> 00:05:59,102 We've got Carl. 125 00:05:59,102 --> 00:05:59,866 >> AUDIENCE: Mitt. 126 00:05:59,866 --> 00:06:01,050 >> STEPHEN TURBAN: Mitt, OK. 127 00:06:01,050 --> 00:06:05,070 And we're going to need a-- I'll be the customer. 128 00:06:05,070 --> 00:06:07,460 So come on up, come on up. 129 00:06:07,460 --> 00:06:10,470 And is everyone in view? 130 00:06:10,470 --> 00:06:15,440 So I'm going to ask Vince to stand in the front, just smiling, 131 00:06:15,440 --> 00:06:18,230 just smiling as bright as possible. 132 00:06:18,230 --> 00:06:21,520 And we're going to ask Carl, right, why don't you, like, 133 00:06:21,520 --> 00:06:24,050 stand right behind her? 134 00:06:24,050 --> 00:06:26,660 And Mitt, why don't you just go off in the back, 135 00:06:26,660 --> 00:06:31,410 and then I'll give you a group of cups to hang out with. 136 00:06:31,410 --> 00:06:34,170 >> So I'm a customer. 137 00:06:34,170 --> 00:06:35,610 I come. 138 00:06:35,610 --> 00:06:40,490 And I make [INAUDIBLE] I say, hi, I'd like a cup. 139 00:06:40,490 --> 00:06:43,214 140 00:06:43,214 --> 00:06:44,580 Perfect. 141 00:06:44,580 --> 00:06:45,580 So Vince has no idea. 142 00:06:45,580 --> 00:06:46,915 So what does Vince do next? 143 00:06:46,915 --> 00:06:50,770 144 00:06:50,770 --> 00:06:52,860 Vince-- OK, so I'm going to be narrating now. 145 00:06:52,860 --> 00:06:55,390 >> Vince shouts at Carl, cup! 146 00:06:55,390 --> 00:06:58,840 147 00:06:58,840 --> 00:07:00,790 What does Carl do? 148 00:07:00,790 --> 00:07:03,910 Carl yells at Mitt. 149 00:07:03,910 --> 00:07:06,710 Mitt grabs a cup. 150 00:07:06,710 --> 00:07:08,220 Mitt gives it to Carl. 151 00:07:08,220 --> 00:07:10,870 Carl returns it to Vince. 152 00:07:10,870 --> 00:07:12,640 And Vince shows it to the user. 153 00:07:12,640 --> 00:07:17,960 >> And that is a high, high, high, so high look at MVC. 154 00:07:17,960 --> 00:07:22,460 We divide it by having a view, what the user sees, a controller, someone 155 00:07:22,460 --> 00:07:25,760 who does everything in the background but really can't update anything 156 00:07:25,760 --> 00:07:29,960 or can't do anything of any significance except calling the view and the model. 157 00:07:29,960 --> 00:07:35,280 And then we have Mitt, the model, who updates whatever data we have. 158 00:07:35,280 --> 00:07:42,660 So thank you so much for our beautiful, controlling, and capable volunteers. 159 00:07:42,660 --> 00:07:43,730 And I think that was it. 160 00:07:43,730 --> 00:07:45,040 >> [APPLAUSE] 161 00:07:45,040 --> 00:07:48,745 >> I think Gabe is going to talk now on a hopefully less high level. 162 00:07:48,745 --> 00:07:51,600 >> GABRIEL GUIMARAES: OK, guys. 163 00:07:51,600 --> 00:07:56,790 Now let's talk a little bit more about code and about Ruby on Rails itself, 164 00:07:56,790 --> 00:08:00,750 and about how it relates to all of this MVC story. 165 00:08:00,750 --> 00:08:03,190 Basically, Ruby on Rails is a framework. 166 00:08:03,190 --> 00:08:04,640 More about that in a second. 167 00:08:04,640 --> 00:08:07,760 >> But just to give you a sense of who's using it, 168 00:08:07,760 --> 00:08:12,240 like, all of these big companies-- so GitHub, Groupon, Twitter-- 169 00:08:12,240 --> 00:08:15,300 they're all using Ruby on Rails as their main framework 170 00:08:15,300 --> 00:08:16,510 to implement their website. 171 00:08:16,510 --> 00:08:19,130 So I'm sure a lot of people have used these websites here. 172 00:08:19,130 --> 00:08:24,470 And it's all Ruby on Rails to implement the model, the view, and the controller 173 00:08:24,470 --> 00:08:26,890 on all of these websites and many more. 174 00:08:26,890 --> 00:08:27,830 OK? 175 00:08:27,830 --> 00:08:32,090 >> So as I said, Ruby on Rails is a framework. 176 00:08:32,090 --> 00:08:37,237 And you can kind of think of a framework in the sense of like building a house. 177 00:08:37,237 --> 00:08:39,570 So if you're going to build a house-- and you can always 178 00:08:39,570 --> 00:08:40,653 start from scratch, right? 179 00:08:40,653 --> 00:08:46,440 You can try to come up with a way to saw the wood, 180 00:08:46,440 --> 00:08:49,760 and to bring the wood to the place, and to get the stones in the right shape, 181 00:08:49,760 --> 00:08:51,250 and then all of that. 182 00:08:51,250 --> 00:08:54,020 But that's going to take probably lots of years 183 00:08:54,020 --> 00:08:56,910 until you get all the material, and you get everything together, 184 00:08:56,910 --> 00:08:58,790 and you actually start to build your house. 185 00:08:58,790 --> 00:09:01,748 >> So it turns out if you start out with a framework with something that's 186 00:09:01,748 --> 00:09:04,260 already kind of in place for any type of house 187 00:09:04,260 --> 00:09:07,750 that you want to build-- something that's very generic but that you can 188 00:09:07,750 --> 00:09:12,850 then model towards your own goals-- then you can leverage 189 00:09:12,850 --> 00:09:16,800 this power of the frameworks to build them something much, much faster. 190 00:09:16,800 --> 00:09:17,300 OK. 191 00:09:17,300 --> 00:09:21,110 So this is the same idea in a framework for a web application 192 00:09:21,110 --> 00:09:23,755 or for any type of application, for that matter. 193 00:09:23,755 --> 00:09:26,560 >> You actually start out with half an application 194 00:09:26,560 --> 00:09:28,400 already there in place for you. 195 00:09:28,400 --> 00:09:32,230 And by that, I mean you get lots of files that already have functions, 196 00:09:32,230 --> 00:09:36,830 like libraries, like functionality, and commands that you can run in order 197 00:09:36,830 --> 00:09:40,500 to make your life much simpler and easier. 198 00:09:40,500 --> 00:09:41,180 OK. 199 00:09:41,180 --> 00:09:43,555 >> So in this case, we're going to talk about Ruby on Rails. 200 00:09:43,555 --> 00:09:45,920 There are lots of different frameworks out there. 201 00:09:45,920 --> 00:09:47,550 There's Django for Python. 202 00:09:47,550 --> 00:09:50,990 There's Zend framework or Laravel for PHP. 203 00:09:50,990 --> 00:09:52,390 There are lots of different ones. 204 00:09:52,390 --> 00:09:56,830 Ruby on Rails is a pretty nice new one. 205 00:09:56,830 --> 00:10:01,600 A lot of people use that in startups and this kind of environment. 206 00:10:01,600 --> 00:10:04,250 And some of these very big companies that I showed here before 207 00:10:04,250 --> 00:10:06,050 are also using Ruby on Rails. 208 00:10:06,050 --> 00:10:10,070 >> So just to give you a sense of what Ruby is 209 00:10:10,070 --> 00:10:13,030 like, since you guys are more used to, like, C and a little bit of PHP 210 00:10:13,030 --> 00:10:17,560 now, so Ruby is going to be the equivalent of your PHP in this sense. 211 00:10:17,560 --> 00:10:18,380 This is not Ruby. 212 00:10:18,380 --> 00:10:19,830 This is C. OK? 213 00:10:19,830 --> 00:10:22,660 But this is like the DJBHash function that I 214 00:10:22,660 --> 00:10:27,170 know many people used for PSET misspellings. 215 00:10:27,170 --> 00:10:29,670 >> And in Ruby, pretty much like in PHP, you 216 00:10:29,670 --> 00:10:32,745 could implement this with only a few lines of code. 217 00:10:32,745 --> 00:10:34,870 Instead of having to worry about the hash function, 218 00:10:34,870 --> 00:10:37,950 having to worry about the buckets, and all of that, you can just say, 219 00:10:37,950 --> 00:10:40,160 dictionary= Hash.net. 220 00:10:40,160 --> 00:10:44,560 And then you use kind of like the same idea that PHP had. 221 00:10:44,560 --> 00:10:45,970 And so it's to true. 222 00:10:45,970 --> 00:10:48,080 And then if you want to check, so check function 223 00:10:48,080 --> 00:10:51,560 would be if dictionary "foo" equals equals true, return true. 224 00:10:51,560 --> 00:10:52,580 And that's all, OK? 225 00:10:52,580 --> 00:10:54,030 >> So you notice a few differences. 226 00:10:54,030 --> 00:10:57,940 There are no semi-colons here, as there were in C. 227 00:10:57,940 --> 00:11:00,710 But the general idea is very similar. 228 00:11:00,710 --> 00:11:02,030 OK? 229 00:11:02,030 --> 00:11:08,010 >> Also, in Ruby, there are gems, which are kind of the Ruby libraries. 230 00:11:08,010 --> 00:11:12,460 And Rails handles them in a very nice way for you. 231 00:11:12,460 --> 00:11:15,480 So if you want to put in some library that 232 00:11:15,480 --> 00:11:18,670 does emails, or that does text messaging, 233 00:11:18,670 --> 00:11:22,170 or that does integration with Facebook, or any kind of thing 234 00:11:22,170 --> 00:11:24,374 like that for your app, it's very, very easy. 235 00:11:24,374 --> 00:11:26,790 Odds are you can find something like that on the internet. 236 00:11:26,790 --> 00:11:30,300 And they just do something like put which 237 00:11:30,300 --> 00:11:32,290 gem you want to use in the gem file. 238 00:11:32,290 --> 00:11:33,749 And then Rails installs everything. 239 00:11:33,749 --> 00:11:36,456 You don't have to worry about any of that, so that's really cool. 240 00:11:36,456 --> 00:11:38,500 Also, there's plenty, plenty of help online. 241 00:11:38,500 --> 00:11:40,485 So you can find lots of things. 242 00:11:40,485 --> 00:11:42,360 If you have an error, you can just Google it, 243 00:11:42,360 --> 00:11:45,090 and it's going to be very easy to get help. 244 00:11:45,090 --> 00:11:47,200 >> And it's a lot of fun-- exactly-- because you 245 00:11:47,200 --> 00:11:51,420 don't have to worry about the low-level details, implementation of hash tables 246 00:11:51,420 --> 00:11:58,080 and having to come up with all of the HTTP headers, and lots of things, 247 00:11:58,080 --> 00:12:00,197 and even some more higher level things. 248 00:12:00,197 --> 00:12:02,030 You don't have to worry about that in Rails. 249 00:12:02,030 --> 00:12:04,010 It does it very, very nicely for you. 250 00:12:04,010 --> 00:12:07,490 And we're going to show that more concretely very soon. 251 00:12:07,490 --> 00:12:08,130 OK. 252 00:12:08,130 --> 00:12:09,750 >> So a little bit about Ruby again. 253 00:12:09,750 --> 00:12:11,420 So it's just like C, as I said. 254 00:12:11,420 --> 00:12:14,170 Instead of printf, we say "puts," which is "put string." 255 00:12:14,170 --> 00:12:18,100 It puts a string to the console. 256 00:12:18,100 --> 00:12:20,601 And in this case, we're just printing "Hello World." 257 00:12:20,601 --> 00:12:23,100 We don't need the parentheses, but it's pretty much similar. 258 00:12:23,100 --> 00:12:26,190 >> And then if you want to do something here, 259 00:12:26,190 --> 00:12:30,450 like print a bunch of "smalls" and a bunch of "bigs" in a While loop, 260 00:12:30,450 --> 00:12:32,060 it's kind of like in C, right? 261 00:12:32,060 --> 00:12:35,090 You don't have the params, but it's pretty much the same. 262 00:12:35,090 --> 00:12:37,300 The indentation here counts, so x equals 1. 263 00:12:37,300 --> 00:12:41,250 And then While x is smaller than 50-- this is an If, this is an Else. 264 00:12:41,250 --> 00:12:42,810 It's pretty much like what you saw. 265 00:12:42,810 --> 00:12:47,150 >> And then x+= 1 is just incrementing, kind of like doing the ++ that you can 266 00:12:47,150 --> 00:12:50,213 do in C. But it's pretty much what you saw in C. 267 00:12:50,213 --> 00:12:52,380 It shouldn't be too complicated. 268 00:12:52,380 --> 00:12:54,320 But it is more powerful. 269 00:12:54,320 --> 00:13:00,100 So there are a few commands here that are definitely a bit newer. 270 00:13:00,100 --> 00:13:05,110 >> So for example, "puts." 271 00:13:05,110 --> 00:13:08,680 You can use this hashtag notation here to just print something-- 272 00:13:08,680 --> 00:13:13,490 pretty much like what you would do if the %D or %C or somewhat like that. 273 00:13:13,490 --> 00:13:17,600 And you can actually put an If right after the statement. 274 00:13:17,600 --> 00:13:21,180 So I only want to do this-- If x is greater than 3. 275 00:13:21,180 --> 00:13:24,129 So why would I have to make an entire If block? 276 00:13:24,129 --> 00:13:24,670 I don't know. 277 00:13:24,670 --> 00:13:28,880 I can just print this only if x equals greater than 3. 278 00:13:28,880 --> 00:13:32,740 So this is a one line way of doing this in Ruby. 279 00:13:32,740 --> 00:13:35,570 >> A list in Ruby is something very versatile. 280 00:13:35,570 --> 00:13:38,110 So you don't really need to have just one type. 281 00:13:38,110 --> 00:13:40,674 You can have a string, and then some numbers, and whatever. 282 00:13:40,674 --> 00:13:42,590 And if you want to append something to a list, 283 00:13:42,590 --> 00:13:46,860 you can just use this notation right here. 284 00:13:46,860 --> 00:13:48,310 >> And if you want to iterate. 285 00:13:48,310 --> 00:13:56,200 Pretty much the 4each in PHP, here, you have a list and you do "List.each do." 286 00:13:56,200 --> 00:13:59,464 And this "elem," this is like the name of each element 287 00:13:59,464 --> 00:14:00,880 that I'm going to have in my list. 288 00:14:00,880 --> 00:14:03,890 And then I can just "puts elem." 289 00:14:03,890 --> 00:14:07,130 And "puts" pretty much handles putting it for you, printing it. 290 00:14:07,130 --> 00:14:09,920 It doesn't matter if it's a string or an int. 291 00:14:09,920 --> 00:14:12,790 It's going to work that out for you. 292 00:14:12,790 --> 00:14:14,270 Right? 293 00:14:14,270 --> 00:14:14,790 Cool. 294 00:14:14,790 --> 00:14:19,980 >> And just like PHP, Ruby and HTML also integrate very, very nicely. 295 00:14:19,980 --> 00:14:23,340 And here, there's some HTML with Ruby in it. 296 00:14:23,340 --> 00:14:25,860 So we have a body tag like in HTML. 297 00:14:25,860 --> 00:14:28,270 And if we want to check that a user is, for example, 298 00:14:28,270 --> 00:14:35,730 logged in, we can just say, beginning of Ruby, if user.logged_in?, end of Ruby. 299 00:14:35,730 --> 00:14:39,240 Print this entire thing, which has some Ruby in it, which is just 300 00:14:39,240 --> 00:14:42,230 kind of like that syntax for PHP that prints out a variable. 301 00:14:42,230 --> 00:14:43,380 Let's print the user.name. 302 00:14:43,380 --> 00:14:48,870 >> So welcome, Stephen, inside of an HTML div. 303 00:14:48,870 --> 00:14:53,760 And at the end, we have an "end" and Ruby code, which means this is my 304 00:14:53,760 --> 00:14:54,470 If block. 305 00:14:54,470 --> 00:14:55,060 OK? 306 00:14:55,060 --> 00:14:57,684 So it's just like a seamless integration between Ruby and HTML. 307 00:14:57,684 --> 00:15:00,056 308 00:15:00,056 --> 00:15:01,430 There are also lots of resources. 309 00:15:01,430 --> 00:15:06,290 But before we move on, does anybody have any questions about Ruby, anything? 310 00:15:06,290 --> 00:15:08,960 OK. 311 00:15:08,960 --> 00:15:12,250 >> There are lots of resources online to tryruby.org, Code Academy, 312 00:15:12,250 --> 00:15:18,740 ruby-lang.org, where you can try it out on your browser before you actually 313 00:15:18,740 --> 00:15:22,310 say, oh, OK, I'm going to use Ruby for my final project. 314 00:15:22,310 --> 00:15:24,020 And so definitely give those a try. 315 00:15:24,020 --> 00:15:26,510 All of these slides are going to be available online, 316 00:15:26,510 --> 00:15:28,950 so you can just download them. 317 00:15:28,950 --> 00:15:30,115 And yes? 318 00:15:30,115 --> 00:15:31,889 >> AUDIENCE: [INAUDIBLE] what you just showed 319 00:15:31,889 --> 00:15:36,851 was HTML and the code embedded into it to this notion of Model View 320 00:15:36,851 --> 00:15:37,350 Controller? 321 00:15:37,350 --> 00:15:37,610 >> GABRIEL GUIMARAES: Yes. 322 00:15:37,610 --> 00:15:40,290 We will do that in a second when we show our example, OK? 323 00:15:40,290 --> 00:15:41,290 Thanks for the question. 324 00:15:41,290 --> 00:15:44,760 So the question was basically if we can show this integration of Ruby 325 00:15:44,760 --> 00:15:49,230 in HTML within the Model View Controller framework. 326 00:15:49,230 --> 00:15:51,710 >> So the idea of the Model View Controller framework 327 00:15:51,710 --> 00:15:55,740 is it's basically a philosophy, just like Stephen showed here. 328 00:15:55,740 --> 00:15:58,177 And it's not something that you have to do, 329 00:15:58,177 --> 00:16:00,510 but it's something that makes your life so much simpler. 330 00:16:00,510 --> 00:16:04,170 And Ruby on Rails is built around this philosophy of code. 331 00:16:04,170 --> 00:16:06,320 So we're going to show an example very soon. 332 00:16:06,320 --> 00:16:07,340 >> So Rails is love. 333 00:16:07,340 --> 00:16:09,140 A lot of people are using it, as I said. 334 00:16:09,140 --> 00:16:10,510 And it's really fun. 335 00:16:10,510 --> 00:16:12,360 You guys should definitely give it a try. 336 00:16:12,360 --> 00:16:15,120 MVC makes everything simpler. 337 00:16:15,120 --> 00:16:18,110 So the Model View Controller, the separating things 338 00:16:18,110 --> 00:16:21,450 and putting one person, per se, or one part of your application 339 00:16:21,450 --> 00:16:24,850 to do each of the different jobs that you application has to do. 340 00:16:24,850 --> 00:16:26,676 And less time spent on low-level problems. 341 00:16:26,676 --> 00:16:27,800 And very popular right now. 342 00:16:27,800 --> 00:16:29,917 We have Rails 4.0, which is a new version. 343 00:16:29,917 --> 00:16:31,500 And it comes with a lot of cool stuff. 344 00:16:31,500 --> 00:16:32,562 Another question. 345 00:16:32,562 --> 00:16:34,490 >> AUDIENCE: Another question. 346 00:16:34,490 --> 00:16:39,310 Ruby on Rails versus Ruby on Rails Grails. 347 00:16:39,310 --> 00:16:40,230 >> GABRIEL GUIMARAES: OK. 348 00:16:40,230 --> 00:16:42,252 The question was, Ruby on Rails versus Ruby-- 349 00:16:42,252 --> 00:16:42,960 AUDIENCE: Grails. 350 00:16:42,960 --> 00:16:43,490 Ruby? 351 00:16:43,490 --> 00:16:44,490 >> GABRIEL GUIMARAES: Yeah. 352 00:16:44,490 --> 00:16:45,955 So Ruby is the language. 353 00:16:45,955 --> 00:16:46,745 >> AUDIENCE: No. 354 00:16:46,745 --> 00:16:50,360 I'm asking you to compare a language and a framework, Ruby on Rails, 355 00:16:50,360 --> 00:16:52,975 with another popular language framework-- Grails-- with Ruby 356 00:16:52,975 --> 00:16:53,310 on Rails. 357 00:16:53,310 --> 00:16:53,720 >> GABRIEL GUIMARAES: OK. 358 00:16:53,720 --> 00:16:54,480 Sorry. 359 00:16:54,480 --> 00:16:57,390 The question was, compare Ruby and Ruby on Rails 360 00:16:57,390 --> 00:16:59,750 to another framework and another-- 361 00:16:59,750 --> 00:17:01,022 >> AUDIENCE: Ruby. 362 00:17:01,022 --> 00:17:01,954 It's OK. 363 00:17:01,954 --> 00:17:03,820 If you don't know about it, that's fine. 364 00:17:03,820 --> 00:17:05,359 >> GABRIEL GUIMARAES: Like, what I understand is that-- 365 00:17:05,359 --> 00:17:07,080 >> AUDIENCE: There's another framework called Grails. 366 00:17:07,080 --> 00:17:07,700 >> GABRIEL GUIMARAES: Oh, Grails. 367 00:17:07,700 --> 00:17:08,650 I never heard of it. 368 00:17:08,650 --> 00:17:09,640 Sorry. 369 00:17:09,640 --> 00:17:11,690 I never heard of Groovy on Rails. 370 00:17:11,690 --> 00:17:12,744 Sorry. 371 00:17:12,744 --> 00:17:14,869 >> AUDIENCE: It's much better integrated with Java. 372 00:17:14,869 --> 00:17:15,450 >> GABRIEL GUIMARAES: I see. 373 00:17:15,450 --> 00:17:17,555 >> AUDIENCE: I'm just curious about some people I know like-- 374 00:17:17,555 --> 00:17:20,240 >> GABRIEL GUIMARAES: No, I never heard of that one, unfortunately. 375 00:17:20,240 --> 00:17:20,700 Grails. 376 00:17:20,700 --> 00:17:21,410 >> AUDIENCE: And some people obviously like Ruby on Rails. 377 00:17:21,410 --> 00:17:22,640 >> GABRIEL GUIMARAES: I've used Ruby on Rails a lot. 378 00:17:22,640 --> 00:17:24,790 I've used some Django with Python, as I said. 379 00:17:24,790 --> 00:17:26,329 I've used some Laravel. 380 00:17:26,329 --> 00:17:29,490 But I hadn't used Groovy on Rails. 381 00:17:29,490 --> 00:17:31,630 Sorry. 382 00:17:31,630 --> 00:17:34,040 And it's very popular now with Rails 4.0. 383 00:17:34,040 --> 00:17:38,180 Like, some of the stuff that Rails does for you, for example, is you 384 00:17:38,180 --> 00:17:43,650 have lots of CSS files and lots of JavaScript files. 385 00:17:43,650 --> 00:17:45,790 And you can treat them as separate and everything. 386 00:17:45,790 --> 00:17:50,010 >> But then it automatically-- when you send your code to production, 387 00:17:50,010 --> 00:17:52,770 it automatically compiles them all into one single file 388 00:17:52,770 --> 00:17:55,150 that's minified without any spaces, so that it takes up 389 00:17:55,150 --> 00:17:59,400 less space in your application, so that you can really scale things a lot. 390 00:17:59,400 --> 00:18:04,380 That's why such big companies like Twitter and GitHub 391 00:18:04,380 --> 00:18:10,220 are using Rails, because it does all that for you, which is really cool. 392 00:18:10,220 --> 00:18:12,840 >> One thing that is very, very, very daunting 393 00:18:12,840 --> 00:18:18,450 for people, including me, who are trying to work 394 00:18:18,450 --> 00:18:22,430 with a framework at the beginning, is that when you start out an application, 395 00:18:22,430 --> 00:18:24,440 you're going to see a bunch of files. 396 00:18:24,440 --> 00:18:28,460 Like, when you create Rails New, My Application, 397 00:18:28,460 --> 00:18:31,710 you're going to see all of these folders-- app, bin, config, db, lib, 398 00:18:31,710 --> 00:18:32,482 log, public. 399 00:18:32,482 --> 00:18:33,690 Like, lots and lots of stuff. 400 00:18:33,690 --> 00:18:35,030 >> And the first time I saw that, I was like, 401 00:18:35,030 --> 00:18:36,570 OK, I have no idea what's going on. 402 00:18:36,570 --> 00:18:38,890 I just want to create a website with "Hello, world," 403 00:18:38,890 --> 00:18:41,730 and this is giving me, like, 100 billion different pages. 404 00:18:41,730 --> 00:18:43,070 I don't know what's going on. 405 00:18:43,070 --> 00:18:47,460 So please do not be too daunted by that. 406 00:18:47,460 --> 00:18:53,699 >> The idea is that it actually has half of a house there for you already. 407 00:18:53,699 --> 00:18:55,490 It has an entire framework for you already. 408 00:18:55,490 --> 00:18:56,948 That's why there are so many files. 409 00:18:56,948 --> 00:19:00,150 But the nice thing is that it separates all of them very nicely. 410 00:19:00,150 --> 00:19:03,370 Odds are you don't have to worry about most of these folders. 411 00:19:03,370 --> 00:19:05,820 >> The most important one, I would say, is the app folder, 412 00:19:05,820 --> 00:19:07,147 where your app actually lives. 413 00:19:07,147 --> 00:19:09,730 So the config, you're going to have to configurate some stuff, 414 00:19:09,730 --> 00:19:12,840 like your database and things like which kind of database you're using. 415 00:19:12,840 --> 00:19:17,430 But other than that, like most of your work is going to be done in app. 416 00:19:17,430 --> 00:19:21,620 So in app, you have assets, controllers, helpers, mailers, models, views. 417 00:19:21,620 --> 00:19:24,460 So here, you start seeing that controllers, models, and views come 418 00:19:24,460 --> 00:19:25,410 into play. 419 00:19:25,410 --> 00:19:27,270 >> Mailers are just if you want to send emails. 420 00:19:27,270 --> 00:19:29,400 Helpers if you want to create some functions 421 00:19:29,400 --> 00:19:32,050 that you use a lot in the view. 422 00:19:32,050 --> 00:19:34,490 So you put them in helpers. 423 00:19:34,490 --> 00:19:39,000 And assets is basically all of your images, all of your CSS, 424 00:19:39,000 --> 00:19:41,200 all of your JavaScript, and like those kinds 425 00:19:41,200 --> 00:19:43,110 of things that get sent to the client. 426 00:19:43,110 --> 00:19:45,500 And everything that's in the assets, that I said before, gets minified. 427 00:19:45,500 --> 00:19:45,940 It's compiled. 428 00:19:45,940 --> 00:19:49,189 And you don't really have to worry about that when it goes to production code. 429 00:19:49,189 --> 00:19:49,770 Cool. 430 00:19:49,770 --> 00:19:54,205 >> Now Zack's going to come in, and he's going to do an example of Twitter50. 431 00:19:54,205 --> 00:19:54,970 >> AUDIENCE: Woo-hoo! 432 00:19:54,970 --> 00:19:56,726 >> ZACK CHAUVIN: Awesome. 433 00:19:56,726 --> 00:20:00,180 So I had the chance to work with Ruby on Rails this summer. 434 00:20:00,180 --> 00:20:01,580 It's an amazing framework. 435 00:20:01,580 --> 00:20:03,580 I'm very partial to it. 436 00:20:03,580 --> 00:20:09,770 And I'll just show you a little bit of an example of what it could look like. 437 00:20:09,770 --> 00:20:11,020 Jump over to Chrome. 438 00:20:11,020 --> 00:20:16,350 So this is an example of a very simple Ruby on Rails application-- something 439 00:20:16,350 --> 00:20:19,690 like this is something that Ruby really excels 440 00:20:19,690 --> 00:20:24,070 that-- just where your models are very well-defined. 441 00:20:24,070 --> 00:20:27,150 >> In this example, you'll see two different models, which 442 00:20:27,150 --> 00:20:30,380 are that we have users and we have tweets. 443 00:20:30,380 --> 00:20:33,480 So this is Twitter50, Harvard's own Twitter. 444 00:20:33,480 --> 00:20:36,820 As you can see, I'm logged in as @zack. 445 00:20:36,820 --> 00:20:38,860 And I'm able to make new tweets. 446 00:20:38,860 --> 00:20:42,266 So I think-- "This is an"-- sorry? 447 00:20:42,266 --> 00:20:43,182 AUDIENCE: [INAUDIBLE]. 448 00:20:43,182 --> 00:20:44,061 ZACK CHAUVIN: Oh, OK. 449 00:20:44,061 --> 00:20:45,060 Need to stop the server. 450 00:20:45,060 --> 00:20:47,480 Excellent. 451 00:20:47,480 --> 00:20:49,630 So here we are. 452 00:20:49,630 --> 00:20:52,520 As you can see, we have our Twitter application right here. 453 00:20:52,520 --> 00:20:55,020 And it's super easy to start the server. 454 00:20:55,020 --> 00:20:57,991 We'll just do "rails server." 455 00:20:57,991 --> 00:20:58,490 Great. 456 00:20:58,490 --> 00:20:58,990 OK. 457 00:20:58,990 --> 00:21:00,830 Thanks for that. 458 00:21:00,830 --> 00:21:02,200 So now we're running. 459 00:21:02,200 --> 00:21:06,120 >> And we'll say, "This is an awesome seminar." 460 00:21:06,120 --> 00:21:08,870 And let's see what happens. 461 00:21:08,870 --> 00:21:10,020 So we'll tweet about it. 462 00:21:10,020 --> 00:21:13,390 Down at the bottom, you can see now there's more than three tweets. 463 00:21:13,390 --> 00:21:15,980 So we have a little bit of pagination going on. 464 00:21:15,980 --> 00:21:19,640 And we have that tweet. 465 00:21:19,640 --> 00:21:24,010 And I can also search through my tweets-- search for this and the two 466 00:21:24,010 --> 00:21:27,960 ones that have the word "this" in them show up. 467 00:21:27,960 --> 00:21:30,860 We can also delete tweets by clicking on the little Delete button. 468 00:21:30,860 --> 00:21:36,440 And obviously, I can only delete the post that belonged to me. 469 00:21:36,440 --> 00:21:39,030 >> Already, we almost have the functionality of Twitter. 470 00:21:39,030 --> 00:21:42,000 Like, when you think about it, Twitter really doesn't do all that much. 471 00:21:42,000 --> 00:21:44,280 It has users, it has tweets. 472 00:21:44,280 --> 00:21:47,690 There's some more complex functionality. 473 00:21:47,690 --> 00:21:52,960 But when you really get down to it, it's quite a simple Ruby on Rails app. 474 00:21:52,960 --> 00:21:57,560 And something like this, with a good understanding of Ruby on Rails, 475 00:21:57,560 --> 00:22:00,680 you could probably make in an hour or two. 476 00:22:00,680 --> 00:22:04,210 >> And that really comes back to the Ruby mantra, 477 00:22:04,210 --> 00:22:07,540 which is convention over configuration. 478 00:22:07,540 --> 00:22:10,965 So back in the day, people, anytime they wanted to make this website, 479 00:22:10,965 --> 00:22:12,340 would have to start from scratch. 480 00:22:12,340 --> 00:22:13,740 OK, I want to make a website. 481 00:22:13,740 --> 00:22:15,970 Let's make this file and this file and this file. 482 00:22:15,970 --> 00:22:19,180 >> With Ruby on Rails, there's none of that. 483 00:22:19,180 --> 00:22:21,170 You say, I want a new app. 484 00:22:21,170 --> 00:22:25,010 And just like Gabe showed us, it creates the whole file structure for us. 485 00:22:25,010 --> 00:22:27,490 And we just change the little parts that we need to. 486 00:22:27,490 --> 00:22:31,570 We just customize what is unique about our app. 487 00:22:31,570 --> 00:22:32,250 Cool. 488 00:22:32,250 --> 00:22:38,540 So going back to our presentation preview-- interesting. 489 00:22:38,540 --> 00:22:41,408 490 00:22:41,408 --> 00:22:42,724 Where do I present? 491 00:22:42,724 --> 00:22:43,640 AUDIENCE: Full screen. 492 00:22:43,640 --> 00:22:45,715 Top right. 493 00:22:45,715 --> 00:22:48,480 >> ZACK CHAUVIN: Excellent. 494 00:22:48,480 --> 00:22:48,990 Cool. 495 00:22:48,990 --> 00:22:49,490 OK. 496 00:22:49,490 --> 00:22:51,480 So first of all, the model. 497 00:22:51,480 --> 00:22:54,100 Stephen did an awesome job of outlining MVC. 498 00:22:54,100 --> 00:22:57,980 And now we're going to relate that back to Ruby on Rails. 499 00:22:57,980 --> 00:23:00,730 So the model you can kind of think of as the database. 500 00:23:00,730 --> 00:23:04,870 You've been seeing this in CS50 Finance, where the model stores 501 00:23:04,870 --> 00:23:07,590 the information about how many stocks you have, 502 00:23:07,590 --> 00:23:10,986 or all the transactions that you made. 503 00:23:10,986 --> 00:23:12,860 This is an example of a line of how you would 504 00:23:12,860 --> 00:23:15,640 go about making a new model in Rails. 505 00:23:15,640 --> 00:23:17,102 So I want a user. 506 00:23:17,102 --> 00:23:19,060 It's going to have an email, which is a string, 507 00:23:19,060 --> 00:23:20,990 and a password, which is also the string. 508 00:23:20,990 --> 00:23:27,150 So it's like those-- I want each row in my table of users to look like that. 509 00:23:27,150 --> 00:23:30,730 >> A really awesome part about Rails is that it 510 00:23:30,730 --> 00:23:33,755 makes it unnecessary to write any SQL pretty much. 511 00:23:33,755 --> 00:23:38,640 How many of you guys loved writing SQL in PSET 7? 512 00:23:38,640 --> 00:23:39,770 Exactly. 513 00:23:39,770 --> 00:23:41,840 SQL is not very user-friendly. 514 00:23:41,840 --> 00:23:46,470 And Rails abstracts all that away with these really easy commands. 515 00:23:46,470 --> 00:23:51,580 So for example, if we have a user, a user has many tweets. 516 00:23:51,580 --> 00:23:56,580 And each one of those tweets belongs to a user. 517 00:23:56,580 --> 00:23:59,520 >> So if you look here, this is our model for our tweet. 518 00:23:59,520 --> 00:24:02,750 And all we have to say is this single line-- I'm a tweet 519 00:24:02,750 --> 00:24:05,090 and I belong to a user. 520 00:24:05,090 --> 00:24:10,160 And with that single line and a little bit of database configuration, 521 00:24:10,160 --> 00:24:12,990 Rails sets up this relationship. 522 00:24:12,990 --> 00:24:17,450 Anytime, I can just say, zack.tweets, like, give me all of Zack tweets. 523 00:24:17,450 --> 00:24:19,420 No SQL. 524 00:24:19,420 --> 00:24:20,040 Super easy. 525 00:24:20,040 --> 00:24:26,580 Again, that's convention over configuration coming into play. 526 00:24:26,580 --> 00:24:29,770 >> You can see a little bit of an example of Ruby here. 527 00:24:29,770 --> 00:24:32,740 Like Gave said, writing Ruby is sort of like writing English. 528 00:24:32,740 --> 00:24:35,540 It's a very high-level language, and it makes it really easy 529 00:24:35,540 --> 00:24:42,380 for us to say things like, I want to make sure that this tweet has a body. 530 00:24:42,380 --> 00:24:43,740 Its presence is true. 531 00:24:43,740 --> 00:24:47,170 And I want to make sure that this tweet, just like normal Twitter, 532 00:24:47,170 --> 00:24:49,020 has a max length of 140. 533 00:24:49,020 --> 00:24:52,800 It's super-intuitive, a really great language. 534 00:24:52,800 --> 00:24:54,590 >> Next up we have the view. 535 00:24:54,590 --> 00:24:57,510 So this involves HTML and CSS. 536 00:24:57,510 --> 00:25:00,490 And here's an example of a view. 537 00:25:00,490 --> 00:25:05,600 So Ruby on Rails kind of seamlessly integrates both Ruby and HTML 538 00:25:05,600 --> 00:25:08,880 in order to generate what we want on the page. 539 00:25:08,880 --> 00:25:11,380 So this is an example of our layout. 540 00:25:11,380 --> 00:25:15,710 So you can see some tags that you guys are used to, like HTML, body, 541 00:25:15,710 --> 00:25:17,250 all that good stuff. 542 00:25:17,250 --> 00:25:21,760 >> And right in here, though, we incorporate some Ruby by saying, 543 00:25:21,760 --> 00:25:25,390 if there's a message to display, then display the message in a div. 544 00:25:25,390 --> 00:25:28,060 So I won't get too much into that. 545 00:25:28,060 --> 00:25:31,190 But this is generally a page that gets rendered on-- 546 00:25:31,190 --> 00:25:33,960 and no matter what page you're on, this one gets rendered. 547 00:25:33,960 --> 00:25:38,110 So this is what gets included always. 548 00:25:38,110 --> 00:25:38,980 Cool. 549 00:25:38,980 --> 00:25:42,730 >> Another example of a view-- this is the one where it chose all the tweets. 550 00:25:42,730 --> 00:25:45,630 And some of this stuff might look pretty familiar. 551 00:25:45,630 --> 00:25:50,050 So for example, right here, we're looping through each of the tweets, 552 00:25:50,050 --> 00:25:51,960 and we're printing them out. 553 00:25:51,960 --> 00:25:54,320 So here is where we're printing out the body. 554 00:25:54,320 --> 00:26:00,910 And if the tweet's user-- here's a real example of no SQL is involved. 555 00:26:00,910 --> 00:26:04,390 I'm just asking, is this tweet's user the current user? 556 00:26:04,390 --> 00:26:06,030 Then show a link to delete it. 557 00:26:06,030 --> 00:26:06,880 It's super simple. 558 00:26:06,880 --> 00:26:09,670 559 00:26:09,670 --> 00:26:10,920 >> The controller. 560 00:26:10,920 --> 00:26:14,390 So this is, again, the interface between the model and the view. 561 00:26:14,390 --> 00:26:17,820 It's the one that does the hard work of interacting-- being the middleman. 562 00:26:17,820 --> 00:26:20,980 It loads information for the view, which we'll see in a sec. 563 00:26:20,980 --> 00:26:23,850 And in order to interact with the model, it 564 00:26:23,850 --> 00:26:29,170 calls model methods, which are what you guys are familiar as functions. 565 00:26:29,170 --> 00:26:31,490 >> So for example, this is our tweet's controller. 566 00:26:31,490 --> 00:26:33,930 It might look a little daunting right now. 567 00:26:33,930 --> 00:26:38,240 But it is actually super intuitive once you start diving in. 568 00:26:38,240 --> 00:26:42,990 So for example, in our index, that's where we want to show all the tweets. 569 00:26:42,990 --> 00:26:46,910 And so this line basically just asks for all the tweets. 570 00:26:46,910 --> 00:26:50,300 And then we initialize both the new tweet-- so like 571 00:26:50,300 --> 00:26:52,320 if they want to create a new tweet on that page. 572 00:26:52,320 --> 00:26:54,250 >> And it asks what the current user is. 573 00:26:54,250 --> 00:26:58,850 And this is very akin to the render that you saw in PSET 7, 574 00:26:58,850 --> 00:27:02,230 where it's just kind of telling the view-- it's kind of, like, 575 00:27:02,230 --> 00:27:06,284 passing the variables that you're going to need in the view to the view. 576 00:27:06,284 --> 00:27:08,200 And there's a whole bunch of different methods 577 00:27:08,200 --> 00:27:10,410 that this tweet's controller can handle. 578 00:27:10,410 --> 00:27:12,495 >> But really, Rails does a great job of kind 579 00:27:12,495 --> 00:27:18,910 of dividing them into the different actions that your controller might do. 580 00:27:18,910 --> 00:27:23,800 Are there any questions about any of the MVC parts of Rails? 581 00:27:23,800 --> 00:27:25,550 Kind of just a breeze by. 582 00:27:25,550 --> 00:27:29,250 So you guys can check it out on your own. 583 00:27:29,250 --> 00:27:30,106 Awesome. 584 00:27:30,106 --> 00:27:31,200 We'll keep going. 585 00:27:31,200 --> 00:27:32,546 >> So installing Rails. 586 00:27:32,546 --> 00:27:35,170 Installing Rails might be, like, one of the more daunting parts 587 00:27:35,170 --> 00:27:37,830 of the whole Rails process, unfortunately. 588 00:27:37,830 --> 00:27:40,450 But obviously, all of us are around to help. 589 00:27:40,450 --> 00:27:42,590 And once it's on there, a lot of great resources, 590 00:27:42,590 --> 00:27:45,100 as Gabe mentioned, for getting started. 591 00:27:45,100 --> 00:27:47,230 Here are the links that you'll need in order 592 00:27:47,230 --> 00:27:51,460 to download Rails to get it installed on your machine. 593 00:27:51,460 --> 00:27:54,240 Obviously, it's available for both Windows and Mac 594 00:27:54,240 --> 00:27:55,600 and for the CS50 appliance. 595 00:27:55,600 --> 00:27:58,520 596 00:27:58,520 --> 00:28:00,020 Questions about anything we've said? 597 00:28:00,020 --> 00:28:04,265 598 00:28:04,265 --> 00:28:06,690 >> AUDIENCE: I would be interested in, actually-- 599 00:28:06,690 --> 00:28:10,255 so I know that downloading software is the biggest barrier. 600 00:28:10,255 --> 00:28:14,807 If there's enough interest to have a downloading mini session or something. 601 00:28:14,807 --> 00:28:15,640 ZACK CHAUVIN: Mm-hm. 602 00:28:15,640 --> 00:28:15,692 Yeah. 603 00:28:15,692 --> 00:28:16,900 That might be really helpful. 604 00:28:16,900 --> 00:28:20,650 If anyone's really gung-ho about using this for their project 605 00:28:20,650 --> 00:28:26,555 or in the future, then we'd definitely be happy to talk to you about that. 606 00:28:26,555 --> 00:28:27,055 Mm-hm. 607 00:28:27,055 --> 00:28:29,530 >> AUDIENCE: A related question to what I asked before. 608 00:28:29,530 --> 00:28:32,563 For those of you who have done other frameworks that are still 609 00:28:32,563 --> 00:28:34,354 trying to do the same thing, make it easier 610 00:28:34,354 --> 00:28:38,452 to build a website or a functionality, I think any sense 611 00:28:38,452 --> 00:28:43,653 of why we would be on Rails versus Zend or some of the other frameworks 612 00:28:43,653 --> 00:28:44,236 and languages. 613 00:28:44,236 --> 00:28:47,870 >> ZACK CHAUVIN: I'll just say my $0.02 about that. 614 00:28:47,870 --> 00:28:49,090 I love Ruby on Rails. 615 00:28:49,090 --> 00:28:52,120 I've had the chance to work in both PHP and Ruby on Rails. 616 00:28:52,120 --> 00:28:55,291 I much prefer Ruby on Rails because of Ruby. 617 00:28:55,291 --> 00:28:56,790 Definitely, that's a big part of it. 618 00:28:56,790 --> 00:28:58,140 Like, when you're choosing your framework, 619 00:28:58,140 --> 00:28:59,490 you also choose your language. 620 00:28:59,490 --> 00:29:03,510 >> Ruby is super accessible-- I think a much better language than PHP. 621 00:29:03,510 --> 00:29:06,250 But that's kind of personal preference. 622 00:29:06,250 --> 00:29:09,360 As well, another consideration is the community behind the framework 623 00:29:09,360 --> 00:29:11,570 that you're working with. 624 00:29:11,570 --> 00:29:13,840 >> Right now Ruby on Rails is really hot. 625 00:29:13,840 --> 00:29:16,160 There's tons of support behind it. 626 00:29:16,160 --> 00:29:19,180 You post something on Stack Overflow about a problem you're 627 00:29:19,180 --> 00:29:22,350 having in Ruby on Rails, and it's answered. 628 00:29:22,350 --> 00:29:26,900 Again, it's open source, which means that it's constantly being changed. 629 00:29:26,900 --> 00:29:28,910 There's tons of people that are really dedicated 630 00:29:28,910 --> 00:29:32,370 in order to making this a really awesome framework. 631 00:29:32,370 --> 00:29:34,225 So that's why I would choose Ruby on Rails. 632 00:29:34,225 --> 00:29:35,225 GABRIEL GUIMARAES: Yeah. 633 00:29:35,225 --> 00:29:37,562 I would say that the idea behind most frameworks you're 634 00:29:37,562 --> 00:29:39,770 going to find out there is very, very similar, right? 635 00:29:39,770 --> 00:29:42,210 So the Model View Controller, the fact that our controller's 636 00:29:42,210 --> 00:29:44,793 going to look like something like this-- each of the functions 637 00:29:44,793 --> 00:29:47,235 is like one of your pages, and it redirects you, 638 00:29:47,235 --> 00:29:48,750 and it initializes the variables. 639 00:29:48,750 --> 00:29:51,959 That's going to be the same thing for every framework that you see out there. 640 00:29:51,959 --> 00:29:53,375 And there's going to be the model. 641 00:29:53,375 --> 00:29:55,270 And you can do stuff like, "belongs to." 642 00:29:55,270 --> 00:29:59,830 So instead of doing the SQL version, you just, like, do, user.tweets, 643 00:29:59,830 --> 00:30:01,210 and you get everything. 644 00:30:01,210 --> 00:30:02,650 Everybody has that. 645 00:30:02,650 --> 00:30:07,070 Except in Ruby, you do user.tweets, and then some frameworks in PHP, 646 00:30:07,070 --> 00:30:12,010 you do user.getalltweets WHERE my PHP is not a problem. 647 00:30:12,010 --> 00:30:13,460 Like, it's a big line. 648 00:30:13,460 --> 00:30:15,320 It's the same thing, but it's a big line. 649 00:30:15,320 --> 00:30:19,350 >> So that's one of the main reasons of my preferences over Ruby. 650 00:30:19,350 --> 00:30:22,290 It's just I do exactly the same thing in other frameworks, 651 00:30:22,290 --> 00:30:26,021 it just takes me twice as long lines of code. 652 00:30:26,021 --> 00:30:26,520 OK? 653 00:30:26,520 --> 00:30:29,730 654 00:30:29,730 --> 00:30:32,540 >> Any other questions? 655 00:30:32,540 --> 00:30:35,200 >> ZACK CHAUVIN: Something I'll mention quickly-- Gabe 656 00:30:35,200 --> 00:30:36,682 talked a little bit about gems. 657 00:30:36,682 --> 00:30:39,890 And that's a really great-- I mean, this is kind of common to all frameworks, 658 00:30:39,890 --> 00:30:45,170 that there's kind of a gem concept, which is like in my little example, 659 00:30:45,170 --> 00:30:46,680 I have login. 660 00:30:46,680 --> 00:30:48,460 Like, you can sign in, sign out. 661 00:30:48,460 --> 00:30:51,740 Like, that's actually kind of a complex process. 662 00:30:51,740 --> 00:30:55,950 It was handled a little bit for you in PSET 7. 663 00:30:55,950 --> 00:31:01,160 But I still don't fully know how to implement sign-in, sign-out. 664 00:31:01,160 --> 00:31:03,740 And that's because Ruby on Rails has tons 665 00:31:03,740 --> 00:31:06,080 of gems that do stuff like that for you. 666 00:31:06,080 --> 00:31:08,550 >> Again, convention over configuration. 667 00:31:08,550 --> 00:31:11,050 Everyone's going to be doing this sign-in, sign-out step. 668 00:31:11,050 --> 00:31:14,450 So why not just make a package, called Devise in this case, which is a gem. 669 00:31:14,450 --> 00:31:15,810 You just include it. 670 00:31:15,810 --> 00:31:18,970 And then there is some help online with how to use it. 671 00:31:18,970 --> 00:31:21,230 And you don't have to worry about anything like that. 672 00:31:21,230 --> 00:31:24,060 >> Attaching pictures to these things-- a gem for that. 673 00:31:24,060 --> 00:31:27,220 Like, anytime you're trying to do anything new, there's a gem for that. 674 00:31:27,220 --> 00:31:29,420 And you kind of just piece together these gems 675 00:31:29,420 --> 00:31:33,160 and build a really complex application very quickly. 676 00:31:33,160 --> 00:31:35,902 677 00:31:35,902 --> 00:31:37,437 Cool. 678 00:31:37,437 --> 00:31:38,270 Any other questions? 679 00:31:38,270 --> 00:31:39,623 >> STEPHEN TURBAN: Woo-hoo. 680 00:31:39,623 --> 00:31:40,976 I don't think [INAUDIBLE]. 681 00:31:40,976 --> 00:31:41,966 >> GABRIEL GUIMARAES: OK. 682 00:31:41,966 --> 00:31:42,840 Thanks so much, guys. 683 00:31:42,840 --> 00:31:43,839 >> STEPHEN TURBAN: Buh-bye. 684 00:31:43,839 --> 00:31:44,850 ZACK CHAUVIN: Buh-bye. 685 00:31:44,850 --> 00:31:45,849 >> STEPHEN TURBAN: Woo-hoo. 686 00:31:45,849 --> 00:31:48,150 [APPLAUSE] 687 00:31:48,150 --> 00:31:49,700 >> Yay. 688 00:31:49,700 --> 00:31:50,955