[Script Info] Title: [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text Dialogue: 0,0:00:16.91,0:00:18.96,Default,,0000,0000,0000,,DAVID PADILLA: All right. Let's get started. Dialogue: 0,0:00:18.96,0:00:21.80,Default,,0000,0000,0000,,Hello everyone. My name is David Padilla. Dialogue: 0,0:00:21.80,0:00:25.91,Default,,0000,0000,0000,,You can find me at dabit. That's my user name Dialogue: 0,0:00:25.91,0:00:27.88,Default,,0000,0000,0000,,on Twitter, on GitHub, and basically Dialogue: 0,0:00:27.88,0:00:32.09,Default,,0000,0000,0000,,everything that matters. Hold on. Dialogue: 0,0:00:32.09,0:00:34.11,Default,,0000,0000,0000,,I work for a company called Crowd Interactive,\Nwhich Dialogue: 0,0:00:34.11,0:00:37.50,Default,,0000,0000,0000,,is a Ruby on Rails consultancy based in Mexico. Dialogue: 0,0:00:37.50,0:00:42.64,Default,,0000,0000,0000,,We also organize the only conference down\Nthere that Dialogue: 0,0:00:42.64,0:00:45.71,Default,,0000,0000,0000,,takes topics like Ruby, JavaScript and all\Nthat. You Dialogue: 0,0:00:45.71,0:00:48.59,Default,,0000,0000,0000,,can go to that website if you want more Dialogue: 0,0:00:48.59,0:00:49.42,Default,,0000,0000,0000,,info. Dialogue: 0,0:00:49.42,0:00:51.64,Default,,0000,0000,0000,,And I'm here to talk to you, or more Dialogue: 0,0:00:51.64,0:00:54.60,Default,,0000,0000,0000,,like to, sort of, how to write web applications Dialogue: 0,0:00:54.60,0:00:58.39,Default,,0000,0000,0000,,with Ruby but not with Rails, nor Sinatra\Nnor Dialogue: 0,0:00:58.39,0:01:01.24,Default,,0000,0000,0000,,Padrino nor any kind of frameworks. Dialogue: 0,0:01:01.24,0:01:03.54,Default,,0000,0000,0000,,First, I want to give you a little bit Dialogue: 0,0:01:03.54,0:01:07.28,Default,,0000,0000,0000,,of background of, of, of why I'm here or Dialogue: 0,0:01:07.28,0:01:11.89,Default,,0000,0000,0000,,where this, where this talk came from. So,\NI Dialogue: 0,0:01:11.89,0:01:18.89,Default,,0000,0000,0000,,basically invented MVC on ASP Classic. I don't\Nknow Dialogue: 0,0:01:19.03,0:01:21.82,Default,,0000,0000,0000,,if you guys are old enough to hear about Dialogue: 0,0:01:21.82,0:01:26.23,Default,,0000,0000,0000,,ASP Classic. Those were the good days. Dialogue: 0,0:01:26.23,0:01:29.61,Default,,0000,0000,0000,,So I invented MVC on ASP. Although not really. Dialogue: 0,0:01:29.61,0:01:33.43,Default,,0000,0000,0000,,Not formally. But, when I was working back\Nthen, Dialogue: 0,0:01:33.43,0:01:35.10,Default,,0000,0000,0000,,my first job, it was ASP, and I was Dialogue: 0,0:01:35.10,0:01:38.25,Default,,0000,0000,0000,,doing things like this. I remember, they threw\Nme Dialogue: 0,0:01:38.25,0:01:40.39,Default,,0000,0000,0000,,into a project that had code like this, that Dialogue: 0,0:01:40.39,0:01:43.27,Default,,0000,0000,0000,,was like a page. They want that ASP. And Dialogue: 0,0:01:43.27,0:01:44.83,Default,,0000,0000,0000,,we had all that code at the beginning where Dialogue: 0,0:01:44.83,0:01:48.17,Default,,0000,0000,0000,,you set up your connection and, and everything\Nrelevant, Dialogue: 0,0:01:48.17,0:01:50.75,Default,,0000,0000,0000,,and then on the, on the body of the, Dialogue: 0,0:01:50.75,0:01:53.47,Default,,0000,0000,0000,,of the, of the page, you have, like, the Dialogue: 0,0:01:53.47,0:01:56.95,Default,,0000,0000,0000,,dynamic stuff and, and, and you ran SQL queries Dialogue: 0,0:01:56.95,0:02:00.30,Default,,0000,0000,0000,,and all that. And then whenever we needed\Nto Dialogue: 0,0:02:00.30,0:02:04.13,Default,,0000,0000,0000,,do another page like this, we would just copy Dialogue: 0,0:02:04.13,0:02:07.66,Default,,0000,0000,0000,,all the code into page two, dot asp, and Dialogue: 0,0:02:07.66,0:02:10.59,Default,,0000,0000,0000,,just change what's relevant. Right? But everything\Nwas copied Dialogue: 0,0:02:10.59,0:02:13.31,Default,,0000,0000,0000,,and pasted into page and page and page, which Dialogue: 0,0:02:13.31,0:02:15.60,Default,,0000,0000,0000,,was kind of odd. Dialogue: 0,0:02:15.60,0:02:17.21,Default,,0000,0000,0000,,So when I, when I, when I began working Dialogue: 0,0:02:17.21,0:02:19.09,Default,,0000,0000,0000,,with this, I was wondering like, how, how\Ncan Dialogue: 0,0:02:19.09,0:02:22.65,Default,,0000,0000,0000,,this be possible. What happens, like, it was,\Nit Dialogue: 0,0:02:22.65,0:02:24.98,Default,,0000,0000,0000,,was painful to change something on the layout,\Nfor Dialogue: 0,0:02:24.98,0:02:27.11,Default,,0000,0000,0000,,example. Just the page title, because you\Nhad to Dialogue: 0,0:02:27.11,0:02:32.12,Default,,0000,0000,0000,,go page one, one by one to change whatever Dialogue: 0,0:02:32.12,0:02:33.95,Default,,0000,0000,0000,,needed to be changed, and it made no sense Dialogue: 0,0:02:33.95,0:02:34.98,Default,,0000,0000,0000,,to me. Dialogue: 0,0:02:34.98,0:02:37.66,Default,,0000,0000,0000,,So I came up with some sort of hack. Dialogue: 0,0:02:37.66,0:02:40.42,Default,,0000,0000,0000,,I changed the code to do something like this. Dialogue: 0,0:02:40.42,0:02:42.67,Default,,0000,0000,0000,,I discovered there was some sort of include,\Nso Dialogue: 0,0:02:42.67,0:02:46.60,Default,,0000,0000,0000,,I said, I, I put all my database stuff Dialogue: 0,0:02:46.60,0:02:49.48,Default,,0000,0000,0000,,in a single file. And then I decided to Dialogue: 0,0:02:49.48,0:02:52.65,Default,,0000,0000,0000,,use the query string to drive to the application Dialogue: 0,0:02:52.65,0:02:55.31,Default,,0000,0000,0000,,and do something like this. So I only had Dialogue: 0,0:02:55.31,0:02:57.94,Default,,0000,0000,0000,,index dot asp, and then through query string\NI Dialogue: 0,0:02:57.94,0:03:01.80,Default,,0000,0000,0000,,said page, product list. And then it, with\Na, Dialogue: 0,0:03:01.80,0:03:03.84,Default,,0000,0000,0000,,with a fancy case, I will say, OK, if Dialogue: 0,0:03:03.84,0:03:06.65,Default,,0000,0000,0000,,it says products then you have to call products Dialogue: 0,0:03:06.65,0:03:09.18,Default,,0000,0000,0000,,dot asp. If it's another page, call this one Dialogue: 0,0:03:09.18,0:03:11.22,Default,,0000,0000,0000,,and so on. And this made things easier. If Dialogue: 0,0:03:11.22,0:03:13.34,Default,,0000,0000,0000,,I needed to change something on the layout,\Nyou Dialogue: 0,0:03:13.34,0:03:15.96,Default,,0000,0000,0000,,will just switch it in index dot asp and Dialogue: 0,0:03:15.96,0:03:17.07,Default,,0000,0000,0000,,not the whole application. Dialogue: 0,0:03:17.07,0:03:19.60,Default,,0000,0000,0000,,Now, before you judge me for this code, let Dialogue: 0,0:03:19.60,0:03:22.16,Default,,0000,0000,0000,,me remind you that it was the year 2000, Dialogue: 0,0:03:22.16,0:03:24.75,Default,,0000,0000,0000,,right. That is Nickelback back there. I was\Nlistening Dialogue: 0,0:03:24.75,0:03:27.29,Default,,0000,0000,0000,,to a lot of Nickelback back then. So you Dialogue: 0,0:03:27.29,0:03:29.88,Default,,0000,0000,0000,,can think where I, where I was, right. So, Dialogue: 0,0:03:29.88,0:03:33.40,Default,,0000,0000,0000,,it's 2000. I moved on from ASP. I went Dialogue: 0,0:03:33.40,0:03:35.90,Default,,0000,0000,0000,,into the world of Java. I learned about Spring, Dialogue: 0,0:03:35.90,0:03:38.55,Default,,0000,0000,0000,,about Struts. And that was when someone introduced\Nme Dialogue: 0,0:03:38.55,0:03:40.57,Default,,0000,0000,0000,,to the concept of MVC, and I was like Dialogue: 0,0:03:40.57,0:03:44.79,Default,,0000,0000,0000,,oh. Yeah. This is what I needed back there, Dialogue: 0,0:03:44.79,0:03:46.21,Default,,0000,0000,0000,,but it didn't exist there. Dialogue: 0,0:03:46.21,0:03:47.65,Default,,0000,0000,0000,,And, and if you think about it, it was Dialogue: 0,0:03:47.65,0:03:49.71,Default,,0000,0000,0000,,sort of the same concept, right. Like, separate\Nyour Dialogue: 0,0:03:49.71,0:03:56.40,Default,,0000,0000,0000,,concerns wherever it matters, and, and stop\Nreusing code, Dialogue: 0,0:03:56.40,0:03:59.41,Default,,0000,0000,0000,,basically. And after a couple of years of\Ndoing Dialogue: 0,0:03:59.41,0:04:02.27,Default,,0000,0000,0000,,Java, I was introduced, then, to Rails. I\Nwas Dialogue: 0,0:04:02.27,0:04:05.58,Default,,0000,0000,0000,,lucky enough to get a job doing Rails programming, Dialogue: 0,0:04:05.58,0:04:06.71,Default,,0000,0000,0000,,and that's what I've been doing for the last Dialogue: 0,0:04:06.71,0:04:10.57,Default,,0000,0000,0000,,seven years. And I've been very happy about\Nit. Dialogue: 0,0:04:10.57,0:04:14.49,Default,,0000,0000,0000,,So, if there's someone that has recently moved\Nfrom Dialogue: 0,0:04:14.49,0:04:17.94,Default,,0000,0000,0000,,Java to Rails understand this feeling. So\NI've been Dialogue: 0,0:04:17.94,0:04:23.29,Default,,0000,0000,0000,,happy for the last seven years. Until I hit Dialogue: 0,0:04:23.29,0:04:29.06,Default,,0000,0000,0000,,what I guess I'd call my mid-programmer life\Ncrisis. Dialogue: 0,0:04:29.06,0:04:32.47,Default,,0000,0000,0000,,This, what happened to me is that I was Dialogue: 0,0:04:32.47,0:04:35.86,Default,,0000,0000,0000,,thinking, that was, that was, those days were\Ncool, Dialogue: 0,0:04:35.86,0:04:37.38,Default,,0000,0000,0000,,where you had all these problems that you\Nneeded Dialogue: 0,0:04:37.38,0:04:40.44,Default,,0000,0000,0000,,to solve with programming and all that stuff.\NAnd Dialogue: 0,0:04:40.44,0:04:42.31,Default,,0000,0000,0000,,right now I think that everything is just\Nthere. Dialogue: 0,0:04:42.31,0:04:44.29,Default,,0000,0000,0000,,You just need to bundle install and the, and Dialogue: 0,0:04:44.29,0:04:45.60,Default,,0000,0000,0000,,the world is solved. Dialogue: 0,0:04:45.60,0:04:49.17,Default,,0000,0000,0000,,So I began thinking, programming web applications\Nwith Rails Dialogue: 0,0:04:49.17,0:04:52.58,Default,,0000,0000,0000,,it's, it's kind of boring. That's, that's,\Nthat's like, Dialogue: 0,0:04:52.58,0:04:56.48,Default,,0000,0000,0000,,I, I, I hit my mid-programmer life crisis,\Nand Dialogue: 0,0:04:56.48,0:04:58.78,Default,,0000,0000,0000,,it's because I began thinking, like, building\Nwebsites with Dialogue: 0,0:04:58.78,0:05:01.29,Default,,0000,0000,0000,,Rails is not enough programming. There's,\Nthere's a lot Dialogue: 0,0:05:01.29,0:05:03.63,Default,,0000,0000,0000,,of magic like, like Akira just said. Just\Na Dialogue: 0,0:05:03.63,0:05:05.93,Default,,0000,0000,0000,,lot of magic going on. It's, it's not enough Dialogue: 0,0:05:05.93,0:05:09.37,Default,,0000,0000,0000,,programming for me. It feels like, if you\Ncalled Dialogue: 0,0:05:09.37,0:05:12.11,Default,,0000,0000,0000,,yourself a great programmer because you do\NRails, it's Dialogue: 0,0:05:12.11,0:05:14.46,Default,,0000,0000,0000,,the same thing as calling yourself a carpenter\Nbecause Dialogue: 0,0:05:14.46,0:05:17.59,Default,,0000,0000,0000,,you bought your carpenter at Ikea, right?\NLike. Yeah. Dialogue: 0,0:05:17.59,0:05:19.93,Default,,0000,0000,0000,,I built that, that, that table. Oh, oh you Dialogue: 0,0:05:19.93,0:05:22.84,Default,,0000,0000,0000,,have skills, right? You know what I mean? Dialogue: 0,0:05:22.84,0:05:26.27,Default,,0000,0000,0000,,And, on top of that, on top of that, Dialogue: 0,0:05:26.27,0:05:28.51,Default,,0000,0000,0000,,things like this happened. If you know Konstantin\NHaase, Dialogue: 0,0:05:28.51,0:05:30.66,Default,,0000,0000,0000,,he was ranting the other day because Rails\Nis Dialogue: 0,0:05:30.66,0:05:33.31,Default,,0000,0000,0000,,like the worst Rack citizen there is. And\Nhe Dialogue: 0,0:05:33.31,0:05:35.30,Default,,0000,0000,0000,,was telling, he was telling us that it was Dialogue: 0,0:05:35.30,0:05:39.13,Default,,0000,0000,0000,,because they never contribute features back,\Nimplemented encrypted sessions Dialogue: 0,0:05:39.13,0:05:41.52,Default,,0000,0000,0000,,in Rails, while it should be on the layer Dialogue: 0,0:05:41.52,0:05:43.86,Default,,0000,0000,0000,,of Rack. You know, things like that. Dialogue: 0,0:05:43.86,0:05:46.33,Default,,0000,0000,0000,,And the problem is that, that we, as Rails Dialogue: 0,0:05:46.33,0:05:49.18,Default,,0000,0000,0000,,programmers, don't want to contribute back.\NIt, it occurred Dialogue: 0,0:05:49.18,0:05:51.34,Default,,0000,0000,0000,,to me that it's maybe because most of us Dialogue: 0,0:05:51.34,0:05:54.26,Default,,0000,0000,0000,,don't know what's going on outside of Rails,\Nright? Dialogue: 0,0:05:54.26,0:05:56.80,Default,,0000,0000,0000,,Like, if, if you were at that last talk, Dialogue: 0,0:05:56.80,0:05:58.71,Default,,0000,0000,0000,,there's all these concepts that we probably\Ndon't know Dialogue: 0,0:05:58.71,0:06:02.07,Default,,0000,0000,0000,,where, do, that they belong to Railties or\Nto Dialogue: 0,0:06:02.07,0:06:04.60,Default,,0000,0000,0000,,Rack or whatever. We just think that everything\Nis Dialogue: 0,0:06:04.60,0:06:05.80,Default,,0000,0000,0000,,Rails, and it's not. Dialogue: 0,0:06:05.80,0:06:07.12,Default,,0000,0000,0000,,And also, well, we used to have all these Dialogue: 0,0:06:07.12,0:06:10.29,Default,,0000,0000,0000,,problems. We used to actually write SQL, you\Nknow, Dialogue: 0,0:06:10.29,0:06:12.16,Default,,0000,0000,0000,,and now we don't do any of that. So Dialogue: 0,0:06:12.16,0:06:15.19,Default,,0000,0000,0000,,maybe, maybe our mind is not challenged enough.\NSo Dialogue: 0,0:06:15.19,0:06:17.99,Default,,0000,0000,0000,,we need to, we need to start thinking about Dialogue: 0,0:06:17.99,0:06:21.31,Default,,0000,0000,0000,,everything that's outside there. We need to\Nbring programming Dialogue: 0,0:06:21.31,0:06:24.86,Default,,0000,0000,0000,,back basically, and so that's why I'm here.\NI'm Dialogue: 0,0:06:24.86,0:06:27.65,Default,,0000,0000,0000,,gonna try to show you how to write a Dialogue: 0,0:06:27.65,0:06:31.76,Default,,0000,0000,0000,,web application with Ruby, but not Rails.\NAnd maybe Dialogue: 0,0:06:31.76,0:06:33.17,Default,,0000,0000,0000,,just a little bit of Rack. Dialogue: 0,0:06:33.17,0:06:36.07,Default,,0000,0000,0000,,You, I'm gonna explain to you a little bit Dialogue: 0,0:06:36.07,0:06:39.64,Default,,0000,0000,0000,,what Rack is. And it's basically just a super Dialogue: 0,0:06:39.64,0:06:44.52,Default,,0000,0000,0000,,cool interface that acts as, yes, an interface\Nbetween Dialogue: 0,0:06:44.52,0:06:47.76,Default,,0000,0000,0000,,web servers and applications. So basically\Nwhat happens is Dialogue: 0,0:06:47.76,0:06:51.86,Default,,0000,0000,0000,,that the web server, whether it is Unicorn,\NPuma, Dialogue: 0,0:06:51.86,0:06:55.07,Default,,0000,0000,0000,,whatever, has to a hash with requests headers,\Nright. Dialogue: 0,0:06:55.07,0:06:57.29,Default,,0000,0000,0000,,And that hash is sent over to the web Dialogue: 0,0:06:57.29,0:07:01.49,Default,,0000,0000,0000,,application that, by convention, needs to\Nbe any object Dialogue: 0,0:07:01.49,0:07:03.49,Default,,0000,0000,0000,,that responds to the call method and receive\Nthat Dialogue: 0,0:07:03.49,0:07:04.73,Default,,0000,0000,0000,,hash. Dialogue: 0,0:07:04.73,0:07:07.07,Default,,0000,0000,0000,,And then the web application does its thing,\Nyou Dialogue: 0,0:07:07.07,0:07:09.21,Default,,0000,0000,0000,,know, and the only thing that it needs to Dialogue: 0,0:07:09.21,0:07:12.05,Default,,0000,0000,0000,,do is return back an array with three elements. Dialogue: 0,0:07:12.05,0:07:14.70,Default,,0000,0000,0000,,One should be the http_code of the response,\Nthat's Dialogue: 0,0:07:14.70,0:07:18.85,Default,,0000,0000,0000,,an integer. The, a hash with all the headers Dialogue: 0,0:07:18.85,0:07:21.89,Default,,0000,0000,0000,,of the response, and a body, which will be Dialogue: 0,0:07:21.89,0:07:25.61,Default,,0000,0000,0000,,any object that can respond to the method\Neach. Dialogue: 0,0:07:25.61,0:07:28.36,Default,,0000,0000,0000,,And that array travels back through the web\Nserver, Dialogue: 0,0:07:28.36,0:07:30.36,Default,,0000,0000,0000,,and then the web server just turns it into Dialogue: 0,0:07:30.36,0:07:36.10,Default,,0000,0000,0000,,something that the browser can understand.\NSo, like I Dialogue: 0,0:07:36.10,0:07:39.18,Default,,0000,0000,0000,,said, like you've heard, all you need to run Dialogue: 0,0:07:39.18,0:07:42.47,Default,,0000,0000,0000,,a Rack application is the file config dot\Nru. Dialogue: 0,0:07:42.47,0:07:47.05,Default,,0000,0000,0000,,And define on that file, using the run directive, Dialogue: 0,0:07:47.05,0:07:50.63,Default,,0000,0000,0000,,the object that will respond to call, and\Nthat Dialogue: 0,0:07:50.63,0:07:54.25,Default,,0000,0000,0000,,will receive that hash of, of headers. Dialogue: 0,0:07:54.25,0:07:57.91,Default,,0000,0000,0000,,So, what you're seeing right here is basically\Nthe Dialogue: 0,0:07:57.91,0:08:02.72,Default,,0000,0000,0000,,smallest but most useless web application\Never. But it's Dialogue: 0,0:08:02.72,0:08:06.71,Default,,0000,0000,0000,,just those three lines and that works. So,\Nthis Dialogue: 0,0:08:06.71,0:08:08.35,Default,,0000,0000,0000,,is the dangerous part. This is where I do Dialogue: 0,0:08:08.35,0:08:11.60,Default,,0000,0000,0000,,some live coding. Call me a rebel if you'd Dialogue: 0,0:08:11.60,0:08:12.33,Default,,0000,0000,0000,,like. Dialogue: 0,0:08:12.33,0:08:16.12,Default,,0000,0000,0000,,So, let's, let's do some live coding. I'm\Ngonna Dialogue: 0,0:08:16.12,0:08:22.96,Default,,0000,0000,0000,,get out this here. And let's begin with that, Dialogue: 0,0:08:22.96,0:08:25.38,Default,,0000,0000,0000,,you can see that, right? Yeah. That's good.\NLet's Dialogue: 0,0:08:25.38,0:08:28.39,Default,,0000,0000,0000,,begin with that config dot ru thing that we Dialogue: 0,0:08:28.39,0:08:31.59,Default,,0000,0000,0000,,mentioned there. We need the run directive\N- we'll Dialogue: 0,0:08:31.59,0:08:38.59,Default,,0000,0000,0000,,create a proc, because a proc can respond\Nto, Dialogue: 0,0:08:39.27,0:08:44.32,Default,,0000,0000,0000,,to call. We'll ask it to print that hash, Dialogue: 0,0:08:44.32,0:08:45.85,Default,,0000,0000,0000,,you know, that we get, that we'll get from Dialogue: 0,0:08:45.85,0:08:50.42,Default,,0000,0000,0000,,the server, and then just answer 200, a hash, Dialogue: 0,0:08:50.42,0:08:54.63,Default,,0000,0000,0000,,and just some empty array, which is an object Dialogue: 0,0:08:54.63,0:08:57.17,Default,,0000,0000,0000,,that responds to each, right. An array can\Ndo Dialogue: 0,0:08:57.17,0:08:58.23,Default,,0000,0000,0000,,that. Dialogue: 0,0:08:58.23,0:09:01.99,Default,,0000,0000,0000,,So, let's see what happens. To start any Rack Dialogue: 0,0:09:01.99,0:09:03.79,Default,,0000,0000,0000,,application, all you need to do is run the Dialogue: 0,0:09:03.79,0:09:06.34,Default,,0000,0000,0000,,rackup command, whatever, to reset that config\Ndot ru Dialogue: 0,0:09:06.34,0:09:09.65,Default,,0000,0000,0000,,file. And then it just boots up basically.\NSo Dialogue: 0,0:09:09.65,0:09:12.86,Default,,0000,0000,0000,,it's telling me that it's booting up on port Dialogue: 0,0:09:12.86,0:09:16.27,Default,,0000,0000,0000,,9292. So if you go to a browser and Dialogue: 0,0:09:16.27,0:09:18.41,Default,,0000,0000,0000,,we reload, there's nothing here because we're\Nnot doing Dialogue: 0,0:09:18.41,0:09:22.34,Default,,0000,0000,0000,,anything. But you can see here that we get Dialogue: 0,0:09:22.34,0:09:23.63,Default,,0000,0000,0000,,that hash, right. Dialogue: 0,0:09:23.63,0:09:25.05,Default,,0000,0000,0000,,This is, this is what the browser sent over Dialogue: 0,0:09:25.05,0:09:28.78,Default,,0000,0000,0000,,to the, to the Rack application, and it got, Dialogue: 0,0:09:28.78,0:09:31.09,Default,,0000,0000,0000,,well, all that information that the browser\Nis sending. Dialogue: 0,0:09:31.09,0:09:35.83,Default,,0000,0000,0000,,So, that is great. Dialogue: 0,0:09:35.83,0:09:40.53,Default,,0000,0000,0000,,Next thing, let's actually do something with\Nthis. So, Dialogue: 0,0:09:40.53,0:09:45.65,Default,,0000,0000,0000,,we're gonna create a body like, like all web Dialogue: 0,0:09:45.65,0:09:50.85,Default,,0000,0000,0000,,application have, and some, well. It will\Nbe body. Dialogue: 0,0:09:50.85,0:09:52.63,Default,,0000,0000,0000,,I'm not very good at html so please forgive Dialogue: 0,0:09:52.63,0:09:58.40,Default,,0000,0000,0000,,me. Let's do Hello World. We'll be, close\Nthe Dialogue: 0,0:09:58.40,0:10:04.40,Default,,0000,0000,0000,,body tag, close the html one. And well. Let's Dialogue: 0,0:10:04.40,0:10:10.100,Default,,0000,0000,0000,,just send that body back. See what happens.\NWe Dialogue: 0,0:10:10.100,0:10:15.28,Default,,0000,0000,0000,,restart our web server. And boom. We have\Na Dialogue: 0,0:10:15.28,0:10:18.32,Default,,0000,0000,0000,,working web application that serves us a single\Npage, Dialogue: 0,0:10:18.32,0:10:18.93,Default,,0000,0000,0000,,basically. Dialogue: 0,0:10:18.93,0:10:22.84,Default,,0000,0000,0000,,All right. Things are working. The problem\Nright now Dialogue: 0,0:10:22.84,0:10:25.27,Default,,0000,0000,0000,,with our web application is that it's only\Nserving Dialogue: 0,0:10:25.27,0:10:27.57,Default,,0000,0000,0000,,one page, no matter what the path is. So Dialogue: 0,0:10:27.57,0:10:31.14,Default,,0000,0000,0000,,if you go, like, to, slash, like the root Dialogue: 0,0:10:31.14,0:10:33.25,Default,,0000,0000,0000,,path, it's Hello World. If you go to slash Dialogue: 0,0:10:33.25,0:10:37.78,Default,,0000,0000,0000,,admin, Hello World. it doesn't matter where\Nyou go. Dialogue: 0,0:10:37.78,0:10:39.88,Default,,0000,0000,0000,,It's always, you know, the same thing. Because\Nwe Dialogue: 0,0:10:39.88,0:10:44.33,Default,,0000,0000,0000,,need something to actually grab the request\Npath and Dialogue: 0,0:10:44.33,0:10:46.43,Default,,0000,0000,0000,,send it over to whatever it needs to be, Dialogue: 0,0:10:46.43,0:10:48.12,Default,,0000,0000,0000,,wherever it needs to go. Dialogue: 0,0:10:48.12,0:10:51.78,Default,,0000,0000,0000,,So, we're gonna use. That's, that's what's\Ncalled a Dialogue: 0,0:10:51.78,0:10:54.42,Default,,0000,0000,0000,,router, usually in the MVC pattern. And the\Nrouter Dialogue: 0,0:10:54.42,0:10:57.90,Default,,0000,0000,0000,,just does, does that. It basically just takes\Nthe, Dialogue: 0,0:10:57.90,0:11:00.73,Default,,0000,0000,0000,,the request path, and then send it over to Dialogue: 0,0:11:00.73,0:11:04.92,Default,,0000,0000,0000,,whoever needs to handle that request. Specifically,\Nthis is Dialogue: 0,0:11:04.92,0:11:10.18,Default,,0000,0000,0000,,very complicated logic, in general. It's way\Nbeyond just Dialogue: 0,0:11:10.18,0:11:13.30,Default,,0000,0000,0000,,doing a case structure. But we'll do that\Nfor Dialogue: 0,0:11:13.30,0:11:14.39,Default,,0000,0000,0000,,now. Dialogue: 0,0:11:14.39,0:11:16.20,Default,,0000,0000,0000,,If you want to learn more about the router Dialogue: 0,0:11:16.20,0:11:19.98,Default,,0000,0000,0000,,in Rails, it's a gem called Journey. And as Dialogue: 0,0:11:19.98,0:11:22.12,Default,,0000,0000,0000,,you can see, it has features and problems,\Nwhich Dialogue: 0,0:11:22.12,0:11:25.27,Default,,0000,0000,0000,,is basically just designed for Rails and that\Nit's Dialogue: 0,0:11:25.27,0:11:28.42,Default,,0000,0000,0000,,too complex right now. And you can imagine\Nwhy. Dialogue: 0,0:11:28.42,0:11:30.73,Default,,0000,0000,0000,,Like, if you, if you define routes, there's\Nall Dialogue: 0,0:11:30.73,0:11:33.83,Default,,0000,0000,0000,,these cases that need to be handled. Whatever\Nyou Dialogue: 0,0:11:33.83,0:11:38.29,Default,,0000,0000,0000,,have. If it, the method, and if you have Dialogue: 0,0:11:38.29,0:11:41.03,Default,,0000,0000,0000,,variables and all that, so it's, it's complex\Nlogic, Dialogue: 0,0:11:41.03,0:11:43.93,Default,,0000,0000,0000,,right. So we're not getting into that. We're\Njust Dialogue: 0,0:11:43.93,0:11:47.54,Default,,0000,0000,0000,,gonna use the same technology that I used\Nten Dialogue: 0,0:11:47.54,0:11:54.24,Default,,0000,0000,0000,,years ago, which is define our case, yay. Dialogue: 0,0:11:54.24,0:11:58.10,Default,,0000,0000,0000,,So, first thing we want to do is say Dialogue: 0,0:11:58.10,0:12:05.10,Default,,0000,0000,0000,,something like path equals env. We're gonna\Nget it Dialogue: 0,0:12:06.37,0:12:09.63,Default,,0000,0000,0000,,from those setters. And then say case path,\Nand Dialogue: 0,0:12:09.63,0:12:14.07,Default,,0000,0000,0000,,you know, when that path is the root path, Dialogue: 0,0:12:14.07,0:12:18.16,Default,,0000,0000,0000,,just serve this. And if it's something else,\Njust Dialogue: 0,0:12:18.16,0:12:24.28,Default,,0000,0000,0000,,say hey, not found. And return a 404, the Dialogue: 0,0:12:24.28,0:12:29.41,Default,,0000,0000,0000,,headers and return that body. And that's it.\NYes. Dialogue: 0,0:12:29.41,0:12:31.33,Default,,0000,0000,0000,,That's our router. Sweet. Dialogue: 0,0:12:31.33,0:12:37.70,Default,,0000,0000,0000,,So. We restart our application and see what\Nhappens. Dialogue: 0,0:12:37.70,0:12:42.100,Default,,0000,0000,0000,,So, now product not found. And if you go Dialogue: 0,0:12:42.100,0:12:46.29,Default,,0000,0000,0000,,to root path, Hello World. Great. So, as you Dialogue: 0,0:12:46.29,0:12:47.99,Default,,0000,0000,0000,,can see, the server is getting the same. You Dialogue: 0,0:12:47.99,0:12:51.36,Default,,0000,0000,0000,,know, it's sending the right codes. 404. 200.\NAnd, Dialogue: 0,0:12:51.36,0:12:54.99,Default,,0000,0000,0000,,and so on. So, we now have some sort Dialogue: 0,0:12:54.99,0:12:57.36,Default,,0000,0000,0000,,of router, right. Dialogue: 0,0:12:57.36,0:13:01.03,Default,,0000,0000,0000,,So, what's next? If we, we probably don't\Nwant Dialogue: 0,0:13:01.03,0:13:05.20,Default,,0000,0000,0000,,to have this code, you know, just pasted in, Dialogue: 0,0:13:05.20,0:13:07.14,Default,,0000,0000,0000,,in our whole, in a single file and do Dialogue: 0,0:13:07.14,0:13:10.50,Default,,0000,0000,0000,,our whole web application here. So let's move\Nthis Dialogue: 0,0:13:10.50,0:13:14.07,Default,,0000,0000,0000,,to a class. To, to make it a little Dialogue: 0,0:13:14.07,0:13:18.93,Default,,0000,0000,0000,,bit more understandable. So I'm gonna steal\Nthis, and Dialogue: 0,0:13:18.93,0:13:23.35,Default,,0000,0000,0000,,I'm gonna put it into a app.rb file. OK. Dialogue: 0,0:13:23.35,0:13:30.04,Default,,0000,0000,0000,,Instead of this, I'm gonna say, like, class\NApp. Dialogue: 0,0:13:30.04,0:13:33.44,Default,,0000,0000,0000,,It has to be, it has to respond to, Dialogue: 0,0:13:33.44,0:13:39.47,Default,,0000,0000,0000,,to call method and receive env, or that hash. Dialogue: 0,0:13:39.47,0:13:41.45,Default,,0000,0000,0000,,And I'm gonna end the method. I'm gonna end Dialogue: 0,0:13:41.45,0:13:45.84,Default,,0000,0000,0000,,that. And ident it. And that's it. Now we Dialogue: 0,0:13:45.84,0:13:49.81,Default,,0000,0000,0000,,have to include that to config dot ru. Dialogue: 0,0:13:49.81,0:13:56.81,Default,,0000,0000,0000,,I'm gonna require that file. And then I'm\Ngonna Dialogue: 0,0:13:58.64,0:14:02.87,Default,,0000,0000,0000,,tell Rack instead of, of doing stuff here,\Njust, Dialogue: 0,0:14:02.87,0:14:06.02,Default,,0000,0000,0000,,you know, send the hash to that, to that Dialogue: 0,0:14:06.02,0:14:08.51,Default,,0000,0000,0000,,class, right. Because now it's an object that\Ncan Dialogue: 0,0:14:08.51,0:14:12.16,Default,,0000,0000,0000,,respond to each. Sorry. To call. Dialogue: 0,0:14:12.16,0:14:14.33,Default,,0000,0000,0000,,So this. Let's just make sure that this is Dialogue: 0,0:14:14.33,0:14:15.90,Default,,0000,0000,0000,,working well. I don't want to write a test Dialogue: 0,0:14:15.90,0:14:20.01,Default,,0000,0000,0000,,for this because, you saw the keynote. So,\Nthere Dialogue: 0,0:14:20.01,0:14:23.66,Default,,0000,0000,0000,,you go. It's still working. We have now abstracted Dialogue: 0,0:14:23.66,0:14:27.80,Default,,0000,0000,0000,,our code to, to, to a class. So that's Dialogue: 0,0:14:27.80,0:14:31.78,Default,,0000,0000,0000,,great. What's next? So, I guess what's next\Nis Dialogue: 0,0:14:31.78,0:14:38.61,Default,,0000,0000,0000,,to go to our, here, and create controllers,\Nright. Dialogue: 0,0:14:38.61,0:14:42.56,Default,,0000,0000,0000,,Instead of having this laying around. We probably\Nwant Dialogue: 0,0:14:42.56,0:14:46.40,Default,,0000,0000,0000,,a class that says, that does this. Dialogue: 0,0:14:46.40,0:14:51.31,Default,,0000,0000,0000,,So let's create a folder real quick that's\Ncontrollers. Dialogue: 0,0:14:51.31,0:14:58.31,Default,,0000,0000,0000,,We'll put them there. And I'll say, let's\Nsay Dialogue: 0,0:15:00.26,0:15:07.26,Default,,0000,0000,0000,,root_controller.rb. What? I know what's gonna.\NHold on. Yeah. Dialogue: 0,0:15:09.11,0:15:15.78,Default,,0000,0000,0000,,root_controller.rb. We say OK. RootController.\NAnd have, I don't Dialogue: 0,0:15:15.78,0:15:18.75,Default,,0000,0000,0000,,know, the action show. This is where code\Nwill Dialogue: 0,0:15:18.75,0:15:23.93,Default,,0000,0000,0000,,be. Dialogue: 0,0:15:23.93,0:15:28.69,Default,,0000,0000,0000,,We probably want to have this controller class\Nreceive Dialogue: 0,0:15:28.69,0:15:35.69,Default,,0000,0000,0000,,that env through the initializer. And then\Nsay, self.env Dialogue: 0,0:15:38.09,0:15:45.09,Default,,0000,0000,0000,,equals env. We added , let's see. And there Dialogue: 0,0:15:48.19,0:15:48.49,Default,,0000,0000,0000,,you go. Dialogue: 0,0:15:48.49,0:15:50.29,Default,,0000,0000,0000,,And here, instead of doing this, we'll just\Nsay Dialogue: 0,0:15:50.29,0:15:57.29,Default,,0000,0000,0000,,RootControll.new, get env and show. We want\Nto require Dialogue: 0,0:16:00.80,0:16:07.80,Default,,0000,0000,0000,,that controller here. And let's make sure\Nthis works. Dialogue: 0,0:16:09.35,0:16:16.35,Default,,0000,0000,0000,,It doesn't. Perks of live coding. I know what Dialogue: 0,0:16:16.75,0:16:23.42,Default,,0000,0000,0000,,it is. Don't worry. OK. K. So. We start Dialogue: 0,0:16:23.42,0:16:26.32,Default,,0000,0000,0000,,our web application and it's still working,\Nwhich is Dialogue: 0,0:16:26.32,0:16:27.100,Default,,0000,0000,0000,,perfect. Dialogue: 0,0:16:27.100,0:16:30.28,Default,,0000,0000,0000,,So what else, what else does a web application Dialogue: 0,0:16:30.28,0:16:36.10,Default,,0000,0000,0000,,need? It needs views, right. We need views.\NWe Dialogue: 0,0:16:36.10,0:16:38.91,Default,,0000,0000,0000,,need to set our html logic. We need to Dialogue: 0,0:16:38.91,0:16:40.58,Default,,0000,0000,0000,,set it apart and put it in a different Dialogue: 0,0:16:40.58,0:16:45.58,Default,,0000,0000,0000,,component. And, that's like the controller\Nhtml pasted into Dialogue: 0,0:16:45.58,0:16:49.92,Default,,0000,0000,0000,,a controller. So let's create views. Hope\Nyou guys Dialogue: 0,0:16:49.92,0:16:54.06,Default,,0000,0000,0000,,like haml. I do. So, we're gonna use that Dialogue: 0,0:16:54.06,0:16:57.05,Default,,0000,0000,0000,,to create our views. First of all, we're gonna, Dialogue: 0,0:16:57.05,0:17:00.99,Default,,0000,0000,0000,,we, we need to create a folder. Views for Dialogue: 0,0:17:00.99,0:17:04.92,Default,,0000,0000,0000,,this controller in specific. All right. Dialogue: 0,0:17:04.92,0:17:11.92,Default,,0000,0000,0000,,So, let's create our views. Show.html.haml.\NWe need, like, Dialogue: 0,0:17:13.06,0:17:20.06,Default,,0000,0000,0000,,head. Title, Railsconf. We'll create a body.\NAnd h1. Dialogue: 0,0:17:24.35,0:17:27.75,Default,,0000,0000,0000,,Something like that. Dialogue: 0,0:17:27.75,0:17:33.93,Default,,0000,0000,0000,,Controllers, root_controller, and then here.\NLet's create a method Dialogue: 0,0:17:33.93,0:17:38.02,Default,,0000,0000,0000,,that will be render. And that method, I want Dialogue: 0,0:17:38.02,0:17:41.30,Default,,0000,0000,0000,,it to receive like the, the, the template\Npath. Dialogue: 0,0:17:41.30,0:17:43.83,Default,,0000,0000,0000,,And what you need to do to, to render Dialogue: 0,0:17:43.83,0:17:46.31,Default,,0000,0000,0000,,like a template with haml and stuff, you need Dialogue: 0,0:17:46.31,0:17:51.76,Default,,0000,0000,0000,,to open the file first and read it. You Dialogue: 0,0:17:51.76,0:17:55.61,Default,,0000,0000,0000,,need to add some sort of variable, which we Dialogue: 0,0:17:55.61,0:18:02.61,Default,,0000,0000,0000,,call template, and then just say, Dear Haml::Engine,\Ncan Dialogue: 0,0:18:03.86,0:18:05.65,Default,,0000,0000,0000,,you please render this? Dialogue: 0,0:18:05.65,0:18:10.66,Default,,0000,0000,0000,,See, it's easy. That's why I chose haml. So Dialogue: 0,0:18:10.66,0:18:13.25,Default,,0000,0000,0000,,we don't need this anymore, because our superview's\Ngonna Dialogue: 0,0:18:13.25,0:18:20.25,Default,,0000,0000,0000,,do it, and we're gonna say render('views/root/show.html.haml').\NAnd I Dialogue: 0,0:18:24.86,0:18:29.12,Default,,0000,0000,0000,,think that's it. We probably just need to\Nrequire Dialogue: 0,0:18:29.12,0:18:35.66,Default,,0000,0000,0000,,haml. We don't want it to blow up. There Dialogue: 0,0:18:35.66,0:18:37.46,Default,,0000,0000,0000,,you go. Dialogue: 0,0:18:37.46,0:18:42.58,Default,,0000,0000,0000,,And, let's see what happens. Yay. We're still\Nthere. Dialogue: 0,0:18:42.58,0:18:45.52,Default,,0000,0000,0000,,So now we have views. The title changed because Dialogue: 0,0:18:45.52,0:18:47.18,Default,,0000,0000,0000,,on that other version, we didn't have. But\Nnow Dialogue: 0,0:18:47.18,0:18:48.79,Default,,0000,0000,0000,,we do. Dialogue: 0,0:18:48.79,0:18:51.89,Default,,0000,0000,0000,,And, the whole point of what we're doing right Dialogue: 0,0:18:51.89,0:18:54.61,Default,,0000,0000,0000,,now, it's because we didn't want to sort of Dialogue: 0,0:18:54.61,0:18:57.29,Default,,0000,0000,0000,,duplicate code and copy and paste, and so\Nwe Dialogue: 0,0:18:57.29,0:18:59.97,Default,,0000,0000,0000,,probably need layouts, right? Like, like,\Nlike with Rails. Dialogue: 0,0:18:59.97,0:19:06.03,Default,,0000,0000,0000,,So, let's create a layout. First thing we\Ndo, Dialogue: 0,0:19:06.03,0:19:13.03,Default,,0000,0000,0000,,views/layouts. Yeah. That'll work. And let's\Nopen what we Dialogue: 0,0:19:13.40,0:19:17.06,Default,,0000,0000,0000,,have right now. And just steal the first four Dialogue: 0,0:19:17.06,0:19:20.99,Default,,0000,0000,0000,,lines. No, actually, we need everything, all\Nthe way Dialogue: 0,0:19:20.99,0:19:22.05,Default,,0000,0000,0000,,here. Yeah. Dialogue: 0,0:19:22.05,0:19:26.63,Default,,0000,0000,0000,,And we indent it. Let's open views/layouts,\Nlet's call Dialogue: 0,0:19:26.63,0:19:33.63,Default,,0000,0000,0000,,it app.html.haml. Views/layouts/app.html.haml.\NAnd here's where we paste it. Dialogue: 0,0:19:37.99,0:19:40.47,Default,,0000,0000,0000,,And, like good old Rails, we're gonna do a Dialogue: 0,0:19:40.47,0:19:43.00,Default,,0000,0000,0000,,yield, and there's where we want the view\Ncode Dialogue: 0,0:19:43.00,0:19:48.51,Default,,0000,0000,0000,,to show up. I'm on time. That's good. Dialogue: 0,0:19:48.51,0:19:53.40,Default,,0000,0000,0000,,We go back to our RootController, and now\Nwe Dialogue: 0,0:19:53.40,0:19:59.57,Default,,0000,0000,0000,,define a method that will be render_with_layout.\NSame thing. Dialogue: 0,0:19:59.57,0:20:03.70,Default,,0000,0000,0000,,We need to know the template path. And let's Dialogue: 0,0:20:03.70,0:20:08.20,Default,,0000,0000,0000,,see, first we open our layout file. We're\Ngonna Dialogue: 0,0:20:08.20,0:20:13.90,Default,,0000,0000,0000,,hard code it because that's how we do. Layouts. Dialogue: 0,0:20:13.90,0:20:20.90,Default,,0000,0000,0000,,No magic here. Read. Dialogue: 0,0:20:24.92,0:20:28.19,Default,,0000,0000,0000,,And do the same thing. Dear Haml::Engine,\Ncan you Dialogue: 0,0:20:28.19,0:20:33.88,Default,,0000,0000,0000,,please render that layout? The trick here\Nis that Dialogue: 0,0:20:33.88,0:20:36.31,Default,,0000,0000,0000,,you can pass a block to render, and then Dialogue: 0,0:20:36.31,0:20:39.64,Default,,0000,0000,0000,,whatever you render inside of the block, that's\Nwhat Dialogue: 0,0:20:39.64,0:20:42.83,Default,,0000,0000,0000,,gets rendered to yield. So we simply call\Nrender Dialogue: 0,0:20:42.83,0:20:45.72,Default,,0000,0000,0000,,again with that template path that we were\Nlooking Dialogue: 0,0:20:45.72,0:20:47.62,Default,,0000,0000,0000,,for up there. Dialogue: 0,0:20:47.62,0:20:54.62,Default,,0000,0000,0000,,So, now we change this code to render_with_layout.\NWe Dialogue: 0,0:20:57.66,0:21:02.99,Default,,0000,0000,0000,,restart our application. And it's still working.\NSo. Now, Dialogue: 0,0:21:02.99,0:21:09.99,Default,,0000,0000,0000,,if I go and change the title, for example, Dialogue: 0,0:21:11.13,0:21:15.08,Default,,0000,0000,0000,,to 2014, then it should, should change. Yay!\NSo, Dialogue: 0,0:21:15.08,0:21:19.14,Default,,0000,0000,0000,,now we have a layout. That's great. And so, Dialogue: 0,0:21:19.14,0:21:22.63,Default,,0000,0000,0000,,what else do we need from web applications? Dialogue: 0,0:21:22.63,0:21:28.42,Default,,0000,0000,0000,,So, we usually need to have dynamic information\Non, Dialogue: 0,0:21:28.42,0:21:31.39,Default,,0000,0000,0000,,on our web application. Something like this.\NLike, maybe Dialogue: 0,0:21:31.39,0:21:34.39,Default,,0000,0000,0000,,the name comes from the database, or comes\Nfrom Dialogue: 0,0:21:34.39,0:21:37.06,Default,,0000,0000,0000,,a query param or whatever. So we need to Dialogue: 0,0:21:37.06,0:21:40.80,Default,,0000,0000,0000,,be able to change data on the views, right. Dialogue: 0,0:21:40.80,0:21:43.58,Default,,0000,0000,0000,,So, let's see if, first of all, we just Dialogue: 0,0:21:43.58,0:21:47.91,Default,,0000,0000,0000,,add that variable there, like, like Rails,\Nas if Dialogue: 0,0:21:47.91,0:21:50.29,Default,,0000,0000,0000,,Rails will do it. But we can see that Dialogue: 0,0:21:50.29,0:21:53.36,Default,,0000,0000,0000,,it's not that easy. It, it doesn't happen\Nmagically. Dialogue: 0,0:21:53.36,0:21:56.03,Default,,0000,0000,0000,,So, what we need to do for this to Dialogue: 0,0:21:56.03,0:21:59.78,Default,,0000,0000,0000,,work is we go back to our controller and, Dialogue: 0,0:21:59.78,0:22:03.44,Default,,0000,0000,0000,,well, first of all, we need to define it, Dialogue: 0,0:22:03.44,0:22:04.48,Default,,0000,0000,0000,,right. Dialogue: 0,0:22:04.48,0:22:07.60,Default,,0000,0000,0000,,Let's say, world. Dialogue: 0,0:22:07.60,0:22:11.77,Default,,0000,0000,0000,,And second of all, the render method can receive, Dialogue: 0,0:22:11.77,0:22:16.11,Default,,0000,0000,0000,,as parameter to context of where the layout\Nis Dialogue: 0,0:22:16.11,0:22:19.61,Default,,0000,0000,0000,,going to be sort of processed. So basically\Nwe Dialogue: 0,0:22:19.61,0:22:21.50,Default,,0000,0000,0000,,just need to tell it the context should be Dialogue: 0,0:22:21.50,0:22:25.74,Default,,0000,0000,0000,,the same object. And, and that way this instance Dialogue: 0,0:22:25.74,0:22:29.75,Default,,0000,0000,0000,,variable will be part of the package. So what Dialogue: 0,0:22:29.75,0:22:34.73,Default,,0000,0000,0000,,we do here is we are going to as- Dialogue: 0,0:22:34.73,0:22:37.69,Default,,0000,0000,0000,,to add the context to our render method. But Dialogue: 0,0:22:37.69,0:22:40.48,Default,,0000,0000,0000,,as default we'll just say hey, just graft\Nself Dialogue: 0,0:22:40.48,0:22:46.51,Default,,0000,0000,0000,,if there's nothing there. Same here. And we\Nneed Dialogue: 0,0:22:46.51,0:22:53.51,Default,,0000,0000,0000,,to pass that context to this render method.\NOver Dialogue: 0,0:22:57.98,0:23:01.91,Default,,0000,0000,0000,,here and over here. So it's all the same. Dialogue: 0,0:23:01.91,0:23:04.62,Default,,0000,0000,0000,,And this is gonna happen sort of magically\Nbecause Dialogue: 0,0:23:04.62,0:23:07.95,Default,,0000,0000,0000,,of that default, where we set it to self. Dialogue: 0,0:23:07.95,0:23:10.28,Default,,0000,0000,0000,,And yay. It's working. Dialogue: 0,0:23:10.28,0:23:14.32,Default,,0000,0000,0000,,So now we can populate that variable or, couple Dialogue: 0,0:23:14.32,0:23:17.27,Default,,0000,0000,0000,,of variables with whatever we want basically.\NThe most Dialogue: 0,0:23:17.27,0:23:21.03,Default,,0000,0000,0000,,typical thing that we could do would be to Dialogue: 0,0:23:21.03,0:23:24.07,Default,,0000,0000,0000,,send it over in a, in, in, in, like Dialogue: 0,0:23:24.07,0:23:28.02,Default,,0000,0000,0000,,params. Like something like this. If it comes\Nas Dialogue: 0,0:23:28.02,0:23:33.81,Default,,0000,0000,0000,,a parameter, do something, or else just do\Nworld, Dialogue: 0,0:23:33.81,0:23:37.40,Default,,0000,0000,0000,,right. But params is a method that we need Dialogue: 0,0:23:37.40,0:23:44.40,Default,,0000,0000,0000,,to basically define. So let's define that.\NParams. I'm Dialogue: 0,0:23:45.21,0:23:48.08,Default,,0000,0000,0000,,not going to write code to like go to Dialogue: 0,0:23:48.08,0:23:53.41,Default,,0000,0000,0000,,a query string. We're just gonna use a method Dialogue: 0,0:23:53.41,0:23:56.99,Default,,0000,0000,0000,,that already exists in Rack::Utils which basically\Ndoes that Dialogue: 0,0:23:56.99,0:24:01.57,Default,,0000,0000,0000,,- parse_nested_query. What it's gonna do,\Nit's gonna take Dialogue: 0,0:24:01.57,0:24:06.93,Default,,0000,0000,0000,,the query string and it's gonna turn it into Dialogue: 0,0:24:06.93,0:24:09.05,Default,,0000,0000,0000,,a nice hash that we can access. So we're Dialogue: 0,0:24:09.05,0:24:13.28,Default,,0000,0000,0000,,gonna add that here in params name and it Dialogue: 0,0:24:13.28,0:24:17.26,Default,,0000,0000,0000,,should work at, at the first attempt. Let's\Ntry Dialogue: 0,0:24:17.26,0:24:17.68,Default,,0000,0000,0000,,it. Dialogue: 0,0:24:17.68,0:24:22.09,Default,,0000,0000,0000,,So, default is Hello, World. It will say name, Dialogue: 0,0:24:22.09,0:24:28.83,Default,,0000,0000,0000,,I don't know, RailsConf, and it works. Hello\NJane Dialogue: 0,0:24:28.83,0:24:32.13,Default,,0000,0000,0000,,or whatever it is, you know. It just works. Dialogue: 0,0:24:32.13,0:24:34.88,Default,,0000,0000,0000,,And, well, I guess the last thing that we Dialogue: 0,0:24:34.88,0:24:37.43,Default,,0000,0000,0000,,could do for a web application will be to Dialogue: 0,0:24:37.43,0:24:42.83,Default,,0000,0000,0000,,properly abstract it. And we probably want\Nto grab Dialogue: 0,0:24:42.83,0:24:45.10,Default,,0000,0000,0000,,all this code and set it on a controller Dialogue: 0,0:24:45.10,0:24:52.10,Default,,0000,0000,0000,,class, right. Because. Over there. And, OK.\NNow, let's Dialogue: 0,0:24:53.75,0:24:58.39,Default,,0000,0000,0000,,go back to our root_controller and just say\Nhey, Dialogue: 0,0:24:58.39,0:25:01.96,Default,,0000,0000,0000,,just inherit from controller. And that's it.\NThat way Dialogue: 0,0:25:01.96,0:25:05.11,Default,,0000,0000,0000,,we can, in the end, we can add more, Dialogue: 0,0:25:05.11,0:25:09.15,Default,,0000,0000,0000,,more and more controllers to our super web\Napplication. Dialogue: 0,0:25:09.15,0:25:11.47,Default,,0000,0000,0000,,The only thing we need to do is require Dialogue: 0,0:25:11.47,0:25:17.88,Default,,0000,0000,0000,,controller. Here, and. Let's make sure that\Nit still Dialogue: 0,0:25:17.88,0:25:18.38,Default,,0000,0000,0000,,works. Dialogue: 0,0:25:18.38,0:25:22.79,Default,,0000,0000,0000,,It still does. That's good. That's always\Ngood. Yup. Dialogue: 0,0:25:22.79,0:25:27.11,Default,,0000,0000,0000,,There you go. So that's it on the coding Dialogue: 0,0:25:27.11,0:25:29.36,Default,,0000,0000,0000,,side. As you can see, you have a working, Dialogue: 0,0:25:29.36,0:25:33.85,Default,,0000,0000,0000,,perfectly working web application right there\Nfrom using no Dialogue: 0,0:25:33.85,0:25:40.85,Default,,0000,0000,0000,,frameworks at all, only your Ruby code. Now,\NI Dialogue: 0,0:25:41.33,0:25:44.13,Default,,0000,0000,0000,,probably don't have the time to add models\Nand Dialogue: 0,0:25:44.13,0:25:48.36,Default,,0000,0000,0000,,all that because that's different logic, but.\NYou could Dialogue: 0,0:25:48.36,0:25:51.20,Default,,0000,0000,0000,,just, you know, inherit ActiveRecord::Base,\Nthey, they, you know, Dialogue: 0,0:25:51.20,0:25:53.68,Default,,0000,0000,0000,,they've already done it. And it's, it's hard\Nlogic Dialogue: 0,0:25:53.68,0:25:54.67,Default,,0000,0000,0000,,you don't need to redo. All you need to Dialogue: 0,0:25:54.67,0:25:57.96,Default,,0000,0000,0000,,do is just, you know, define classes and say, Dialogue: 0,0:25:57.96,0:26:00.44,Default,,0000,0000,0000,,inherit from ActiveRecord::Base, and you will\Nget, like, all Dialogue: 0,0:26:00.44,0:26:02.13,Default,,0000,0000,0000,,the magic that you get on Rails. Dialogue: 0,0:26:02.13,0:26:03.72,Default,,0000,0000,0000,,If you're a little bit more hardcore, then\Nyou Dialogue: 0,0:26:03.72,0:26:06.90,Default,,0000,0000,0000,,can use sequel, and just write your methods\Nlike Dialogue: 0,0:26:06.90,0:26:09.19,Default,,0000,0000,0000,,so, and you can get access to the database Dialogue: 0,0:26:09.19,0:26:11.60,Default,,0000,0000,0000,,that's, as if it was a hash, and just Dialogue: 0,0:26:11.60,0:26:13.68,Default,,0000,0000,0000,,write your dot all, your dot find, all that Dialogue: 0,0:26:13.68,0:26:17.15,Default,,0000,0000,0000,,logic. And if you're even more hardcore, you\Ncan Dialogue: 0,0:26:17.15,0:26:20.60,Default,,0000,0000,0000,,directly use the pg gem or the mysql gem, Dialogue: 0,0:26:20.60,0:26:24.03,Default,,0000,0000,0000,,and just, you know, do this sort of crazy Dialogue: 0,0:26:24.03,0:26:27.51,Default,,0000,0000,0000,,stuff where you actually write SQL. Yay SQL.\NAnd Dialogue: 0,0:26:27.51,0:26:30.74,Default,,0000,0000,0000,,then just, you know, iterate through the results\Nand Dialogue: 0,0:26:30.74,0:26:32.67,Default,,0000,0000,0000,,put them in the hash and all that. This Dialogue: 0,0:26:32.67,0:26:35.43,Default,,0000,0000,0000,,is, this is fun. Like, this is programming,\Nright. Dialogue: 0,0:26:35.43,0:26:39.77,Default,,0000,0000,0000,,And one last piece of advice I have for Dialogue: 0,0:26:39.77,0:26:46.45,Default,,0000,0000,0000,,you is don't ever actually do this. Don't\Never Dialogue: 0,0:26:46.45,0:26:49.08,Default,,0000,0000,0000,,actually do this unless you're some sort of\Nspeed Dialogue: 0,0:26:49.08,0:26:52.27,Default,,0000,0000,0000,,freak or performance freak. When I run my\Ntests, Dialogue: 0,0:26:52.27,0:26:55.67,Default,,0000,0000,0000,,my super web application was able to handle\N700 Dialogue: 0,0:26:55.67,0:26:59.36,Default,,0000,0000,0000,,requests per second, and every request will\Ntake one Dialogue: 0,0:26:59.36,0:27:03.35,Default,,0000,0000,0000,,millisecond, which is pretty fast, right.\NBut when I Dialogue: 0,0:27:03.35,0:27:06.40,Default,,0000,0000,0000,,created the same application using Rails,\NI had like Dialogue: 0,0:27:06.40,0:27:11.55,Default,,0000,0000,0000,,2x slowness, right, right. It will take two\Nmilliseconds Dialogue: 0,0:27:11.55,0:27:14.15,Default,,0000,0000,0000,,to, to run, which is unacceptable. I want\None Dialogue: 0,0:27:14.15,0:27:18.47,Default,,0000,0000,0000,,milliseconds. But this is unfair because Rails\Nsolves all Dialogue: 0,0:27:18.47,0:27:21.53,Default,,0000,0000,0000,,these problems, right. We have logging, caching,\Ndatabase pooling, Dialogue: 0,0:27:21.53,0:27:24.12,Default,,0000,0000,0000,,sessions, cookies, security, all of that,\Nthat we're not Dialogue: 0,0:27:24.12,0:27:27.85,Default,,0000,0000,0000,,considering on our own application. Dialogue: 0,0:27:27.85,0:27:28.83,Default,,0000,0000,0000,,But even if you don't want to do this Dialogue: 0,0:27:28.83,0:27:31.20,Default,,0000,0000,0000,,in real life, you do want to read code, Dialogue: 0,0:27:31.20,0:27:33.29,Default,,0000,0000,0000,,and you do want to go and, and, and Dialogue: 0,0:27:33.29,0:27:36.83,Default,,0000,0000,0000,,try and see how Rails is doing things. You Dialogue: 0,0:27:36.83,0:27:40.03,Default,,0000,0000,0000,,want to try to understand, how is it doing Dialogue: 0,0:27:40.03,0:27:43.51,Default,,0000,0000,0000,,it? Like, right, you want to do find that Dialogue: 0,0:27:43.51,0:27:46.10,Default,,0000,0000,0000,,code that connects to the database, that code\Nthat Dialogue: 0,0:27:46.10,0:27:50.14,Default,,0000,0000,0000,,turns dot find into select star from that\Ntable, Dialogue: 0,0:27:50.14,0:27:52.02,Default,,0000,0000,0000,,you know, all that, you want to go and Dialogue: 0,0:27:52.02,0:27:54.41,Default,,0000,0000,0000,,read and try to understand how things work.\NAnd Dialogue: 0,0:27:54.41,0:27:57.57,Default,,0000,0000,0000,,then once you understand, try to write your\Nown Dialogue: 0,0:27:57.57,0:28:02.02,Default,,0000,0000,0000,,framework. Well, why not? There's, there's\Nspace for, for Dialogue: 0,0:28:02.02,0:28:04.17,Default,,0000,0000,0000,,a new framework. Maybe, maybe you'll be the\Nnext Dialogue: 0,0:28:04.17,0:28:08.59,Default,,0000,0000,0000,,DHH and will, and will be able to afford Dialogue: 0,0:28:08.59,0:28:11.43,Default,,0000,0000,0000,,and race car and all that. Dialogue: 0,0:28:11.43,0:28:12.85,Default,,0000,0000,0000,,But the most important thing is that you will Dialogue: 0,0:28:12.85,0:28:17.25,Default,,0000,0000,0000,,understand, like, master this topic. You will\Nknow, you, Dialogue: 0,0:28:17.25,0:28:19.46,Default,,0000,0000,0000,,you will have that feeling of saying, hey,\NI Dialogue: 0,0:28:19.46,0:28:20.99,Default,,0000,0000,0000,,know how this works. This is great, now I Dialogue: 0,0:28:20.99,0:28:27.18,Default,,0000,0000,0000,,can go back to doing my Ikea software. But Dialogue: 0,0:28:27.18,0:28:30.78,Default,,0000,0000,0000,,I at least I know how it works, right. Dialogue: 0,0:28:30.78,0:28:32.97,Default,,0000,0000,0000,,And then if you see the Rails core team, Dialogue: 0,0:28:32.97,0:28:35.28,Default,,0000,0000,0000,,give them a hug. Because you will understand\Nalso, Dialogue: 0,0:28:35.28,0:28:37.18,Default,,0000,0000,0000,,like, the pain that they had to go through Dialogue: 0,0:28:37.18,0:28:40.54,Default,,0000,0000,0000,,to get Rails to where it is right now, Dialogue: 0,0:28:40.54,0:28:42.44,Default,,0000,0000,0000,,because it's not easy, right. We just, we\Njust Dialogue: 0,0:28:42.44,0:28:45.36,Default,,0000,0000,0000,,wrote like thirty minutes of code, but it\Ndoes Dialogue: 0,0:28:45.36,0:28:47.48,Default,,0000,0000,0000,,basically nothing. It needs to take care of\Nrouting, Dialogue: 0,0:28:47.48,0:28:51.09,Default,,0000,0000,0000,,like I said, caching, security, and all that.\NAnd Dialogue: 0,0:28:51.09,0:28:52.97,Default,,0000,0000,0000,,that's, you know, a lot of lines of code Dialogue: 0,0:28:52.97,0:28:55.62,Default,,0000,0000,0000,,that need to, that need to happen. So, so Dialogue: 0,0:28:55.62,0:28:57.87,Default,,0000,0000,0000,,you see a Rails core guy, you say, hey, Dialogue: 0,0:28:57.87,0:29:00.92,Default,,0000,0000,0000,,thanks for that. Give him a hug. And my Dialogue: 0,0:29:00.92,0:29:03.05,Default,,0000,0000,0000,,last disclaimer is that I do not actually\Nthink Dialogue: 0,0:29:03.05,0:29:05.50,Default,,0000,0000,0000,,that writing web applications with Rails is\Nboring. That Dialogue: 0,0:29:05.50,0:29:07.74,Default,,0000,0000,0000,,was just added for drama. Dialogue: 0,0:29:07.74,0:29:12.25,Default,,0000,0000,0000,,And I hope you understand that. That's it.\NI Dialogue: 0,0:29:12.25,0:29:15.09,Default,,0000,0000,0000,,will Tweet or, whenever you see the slides\Nyou Dialogue: 0,0:29:15.09,0:29:17.33,Default,,0000,0000,0000,,will see like the code example on, on my Dialogue: 0,0:29:17.33,0:29:20.02,Default,,0000,0000,0000,,talk on that, on that url. And thank you.