 So, once again, this is the Wi-Fi password and the Wi-Fi network is also the password. So, we can only connect up to 80 devices, so if your phone is on the Wi-Fi, you can switch it off so that someone else can get connected. So, if you need power, the silver boxes on the floor, that's actually the electric plug. You should have enough. If you don't have enough, we also have the extension right up here in front. So, if you need it, just raise your hand and we will get to you. Yeah, the bathroom is at the door there. So, you need to get through the door and find the red door that will lead you to the bathroom. Okay, so now we're ready to start. So, you are here because of our Tech Ladies Bootcamp. If you don't know what it is, I'm going to tell you. So, the Tech Ladies Bootcamp is a 10-week part-time program where we teach you how to code. For NGOs. So, you will work in groups of three to create a product for a non-profit organization. And the rest you can read. For the second bootcamp, we are only going to be teaching you the Ruby programming language, which is kind of the language that we have been using since the first workshop. There will be five coaches helping five NGOs. So, we will be selecting 15 participants for this batch. So, we will start the program on 24th of September and we'll meet every Saturday. Around this time, like one to five, every Saturday. But you're expected to code on your own during the week. So, it costs $500 to participate. Scholarships are available. If you need a scholarship, it's also on the application form. So, for more details on the bootcamp, go to this website. So, you might want to...it's actually kind of like everywhere already, but if you need, just take a photo of this slide. Okay, I think we all have that. So, one thing is very, very important. The application closes on 2nd of September. That gives us about a couple of weeks. So, to apply, you will need to complete a technical task. And this is the technical task. So, create an app. Push it on the GitHub. Deploy it on Heroku. So, if you keep hearing us say, oh, do you have a GitHub Heroku? That's because we want you to get ready for the task. So, we don't care what app you want to do. I know some of the participants, they want to do like a puzzle app. Just feel free to run free. Go crazy. Some ideas for you is a travel wish list app. You can just create an article of the countries you want to go, when do you want to go, and maybe why do you want to go. The stretch goals are completely optional. It's up to you if you want to try and learn how to do that too. The second idea is a personal blog. So, you have a blog post, a blog... and there's a page where you can see all the blog posts. Or you can do an event listing app. So, it's kind of like Eventbrite where you sign up for this workshop form. And the fourth idea that we have for you is to like a magic eight ball. Just insert any random text and it will give you more random text back. So, I know that all of you are beginners and if you need any help, sometimes it's easier. It's really a lot easier if you also post a screenshot because it's just a lot easier to explain your problem where we can see what kind of error messages you are receiving. So, take a screenshot of wherever you have started and post the question on the Facebook group. So, do it at the group, don't do it at the page because I meant the page and I'm not that technical. So, sometimes I'm like, I cannot help you. So, if you need some sort of advice on how you can structure whatever application you want to build, also do it at the group. Or you can just ask, grab one of the coaches today during the break or after the workshop. So, some tips that I thought might be useful for you when you're trying to learn how to code. So, before you recognize that it is a problem, like run through these sanity checks. Like, did you save your file? Because sometimes on nitrous, if you don't save your file, it will appear as a little circle and your codes wouldn't run because you haven't saved it yet. So, check if you have saved your file. The second thing is check if you're in the right folder. Sometimes if you do a git status, you wouldn't show you stuff or you're trying to do any funky git stuff or trying to start your server. But if you're in the wrong folder, then you're in the wrong universe and you wouldn't work. So, make sure that you're in the right folder. The third one, I think it's more relevant if you're only using nitrous. Because sometimes nitrous, they just switch off your server for whatever reason. So, if you want to refresh your page, you'll realize you'll see this gray, depressingly gray page telling you your server isn't like switched on. So, you might want to start your server again. In some cases, when you are creating or updating your database, which we'll talk more about it later, like what is this database thing, you might need to restart your server. Or like some strange reason, I don't really know, there are some situations where you need to restart your server. So, just try restarting it to see if things work. So, again, these are the important dates. For the bootcamp. If this is the first time you're at this workshop, how we work is there will be a head coach. Ted over here will lead the entire session. If you have any questions or like stuff don't work as expected, just raise your hand. We have a lot of assistant coaches today who will help you out. So, what we're going to do now is we will have the assistant coaches stand up. Then we'll go like one round where they will just yell out their name and we'll say hi, name. We'll start from Wei Liang. Hi, I'm Wei Liang. Hi, Wei Liang. Ladies, you need to say hi to the assistant coach. Hi. Okay, Alan. Hi. Hi. Oh, okay. Hi, I'm Sherwin. Hi, Sherwin. Hi, I'm Dragosh. Hi, Dragosh. Hi, Michael. Hi, Michael. Okay, great. So, let's start the workshop proper. You want to flash the slides and tell them a link. Yeah, it's in there. Here you go. Okay, I lost my mouse. Oh, right there. What if I pass it? My keynote. And let me take a photo of it. Here's my mouse. So, this is the third installment and the final installment of the three part tech ladies workshop. So, for the benefit of the assistant coaches, let's do a show of hands. If this is the first workshop, the first tech ladies workshop that you attend, please raise your hand. Right? If this is the second tech ladies workshop, please raise your hand now. Right? And if you've been to all three workshops, please raise your hand. Right? Great, so there are a lot of people who actually attended all the workshops. So, in this final workshop, this workshop will hopefully help you prep a lot for the technical task which is the entry requirement for the boot camp. And I'll be doing a lot of slides. And one of the feedbacks from the previous workshops was that if you encounter some problem, you sort of fall behind and you miss out on some of the slides. So, for this workshop, the slides are available at this URL. So, I recommend you all to open up this in a separate tab. So, I think it's inevitable to some problems, but if you do, you don't have to be afraid that you'll miss out on the slides because they're all available here. So, I'll give you all a minute or two to open this up. Alright, so hopefully by now, everyone has set up either a nitrous account and started a Ruby on Rails project. And the slides are assuming that you're using nitrous. So, if you want to use a local installation of Ruby and Rails, some of the commands will be slightly different. But if you have any problems, you can just raise your hand and your friendly coaches will come and help you out. If you have neither a nitrous account or a local installation right now, then this is definitely the time to raise your hand to get some help. So, in this third and final workshop, we'll be learning about Rails and we'll continue building the guest a number game that we've been using as the example in the previous workshops. So, Rails is a framework for building web applications and it's written entirely in Ruby. You can actually go and see all the source code for Rails hosted on GitHub. And what the framework does, it basically gives you a bunch of high-level building blocks that help you build a certain kind of application and in our case, a web application because we want to host the application on the Internet. So, Rails is built on what is called the MBC pattern. And you can think of the MBC pattern as what is called as a layered architecture. And much like a cake that has different layers, Ruby and Rails also has three different layers where each layer has a particular responsibility and the layers in the case of Rails are the models, the views and the controllers, so MBC. In MBC, our models are used to describe objects in our business domain and also to model their relationships. And in Rails, they can also be responsible for some other things like saving our data to a database or validating that the data is correct. The view layer, on the other hand, is responsible for presenting the data to the end user. And in the case of Rails, this is done through web pages, so for those of you who were at the previous workshop, you will be familiar with the HTML and ERB templates. So it mostly play in HTML, but it also allows you to use some Ruby code in there. Finally, in Rails, there's the controller, and the controller acts like sort of a thin layer of glue that will connect your view layer or the user interface with the models that are capturing the data of your application. So in the previous workshop, it was previously covered how request and responses are sent over the internet to our application. And from the perspective of the hardware, you have a client that can be a laptop or it can be a phone or a desktop computer where a user is browsing the internet, and it will send a request to a server which will send a response back to the client. And the jargon we use for this is usually front-end and back-end, so you'll probably hear these terms thrown around a lot if you talk to developers. And it's roughly the same as talking about the client and the server. If you start looking at the software that is actually sending the requests, on the front-end you will normally have something like a web browser that is responsible for sending the request to the server and rendering the HTML templates that it gets back as a response. And of course, on the server, the software we're running is Ruby on Rails. So we talked a little bit about the architectural layers, the models, views, and controllers. But of course these don't really correspond to any of our business domain objects. So Rails is also based around something called resources and something called restful routing. So if we take the cake from before where the horizontal layers correspond to the models, the views, and the controllers, we can think of a resource like a slice out of the cake. So each resource will have its own model, it will have its own controller, and it will have its own set of views. And on these resources, we can form a set number of actions. And these actions are normally remembered through the mnemonic CRUD. And CRUD stands for create, read, update, and delete. So these four basic actions are normally available on resources. It's worth noting that in Rails, there are also other controller actions in addition to these. And these are used to render the forms that are needed to create and update our resources. And we'll talk a little bit more about what the difference between CRUD and controller actions are later. So I hope now that everyone has nitrous up and running with a Rails template. If not, you can call on one of the coaches to help you out. So the first thing we're going to do is to create our first resource. But before we do that, or anything else for that matter, there's another important thing that we should do first. So if you were at the previous workshop, you're probably somewhat familiar with the git. So at certain points throughout this workshop, we're actually going to commit our work so that in the case that we do something horribly wrong, then we can easily revert back to a working version of our code. So the first thing you need to do is to go into your terminal, change the working directory to the directory of your application, and if you're using nitrous, it's in the directory code slash example. For the benefits of the other coaches on the floor, this is a very common source of problems. You need to make sure that you're in the right directory when you run the terminal commands because a lot of times you're in some other directory and the commands won't work, so it's a good sanity check to see that you're always in the right directory. So once you've changed to the right directory, you will use git init to set up a new git repository. Following git init, you need to do git add dash a and what the dash a does is it adds everything, including things that were deleted and empty folders and such. And finally, you need to commit your work. So for commit, when you pass it the dash m flag, it allows you to input a commit message inside quotation marks and it's common to call the first commit of a project initial commit. Using nitrous, after you do git init, you hopefully see your terminal prompt change and in addition to the directory you're in, it will also tell you which git branch you're using. But most of you have managed to commit your work into git now, so we're going to move on to the next slide. So let's go back to adding our first resource to our Rails application. So we're building, I guess, the number of game and the first resource we want is probably a game resource so that we have something in our application that actually represents one single playthrough of the game. So Rails comes with a bunch of built-in generators and what these generators do is they basically write a lot of code for you and with doing that it also makes a lot of assumptions about the code that it writes. What we're going to use is to generate the first game resource. So in Rails your resources will have attributes and in this case we will give our game resource two attributes. The first one is the number or the secret number that will be the correct guess for this particular instance of the game. The second attribute will be a completed attribute that will tell you whether the game has finished playing or not. So if you're familiar with the types from the first workshop you can see that the number will be an integer or a whole number and the completed attribute will be true or false for a Boolean value. Also take note that all these should go on the same line it just couldn't fit on one line in the slides. You will get a huge list of files that were automatically generated by our Rails generator. So Rails actually comes with a bunch of different generators and in this case we're using the scaffold generator which will give us the most complete set of files needed for our resource. I'll move to the next slide but if you're not done with this yet you always have the slides available at the URL shown initially. So before we can test the code that was generated out we need to migrate our database. So what do I mean by that? Well in Rails when you change the database it is done through Ruby code files that are code migrations and this allows us to easily see the history of what changes have been done to the database and also to roll back changes that we didn't actually want. So in order to actually run your migrations which will create the new table for the games in our database you need to run the command rake dbmigrate in your terminal. So some of them are still having internet problems so I call the value person to see if there's anything we can do or give them updates. In the meantime they can try to take them in from their phone or ask someone beside them to share their laptop with them. So what I'm going to need is to tell all of these to the participants and also for people who are having problems with the internet raise their hand so that we can go help them to pair up with someone else. So it seems some of you still have issues connecting to the Wi-Fi. If you have those issues please raise your hand. So we've contacted the owners of the venue to help us out with this but in the meanwhile hopefully we can come to some other solution where we can use Ted the Ring from our phone or pair you up with someone else. But please keep your hand up so someone can come over and help you. Alright, hopefully by now most of you have migrated your databases. So we're going to test some of our code out and I'm going to introduce you to something which is called the Rails console and it's very similar to the interactive Ruby environment that you tried out in the first workshop. The difference is that it also has all your Rails stuff loaded in there so you can use the terminal to play around with the resources that we just created. And the Rails console is something that is used quite extensively by developers to test out their code. So you can get into the Rails console by typing Rails console in the terminal and make sure that you're in the right directory when you type this or it won't work at all. And once you load the console up try to type game.all and see what happens. And this game.all is just regular Ruby code. Everything magical going on in there. And if everything went well with generating our resource and migrating our database, it will load up all our games from our database but at the moment we don't have any games in there so it will just be an empty list. But if any of this doesn't work then please raise your hand so a coach can come over and help you. Alright so when you're done with your console rights in order to exit the console you can either do control D or you can type exit into the console and press enter. Hopefully you're all somewhat familiar with the console by now and you've also been able to exit the console using control D or typing exit. So in addition to a modular controller and some views our generator also added some routes for us. And I know from the second workshop there was a short walkthrough about routing but a route is basically a URL that will be used to access the resources in your application. So all routes for an application are defined in a single file that is located in the config directory. So you can go ahead and open up this file now to see what's inside. And when I say open up this file this is not a command to type in the terminal you should just open this file in your IDE. So inside your routes file at the bottom there will be a whole bunch of comments that were generated by Rails to add some documentation on how to use the routes. If you want to you can keep these comments but I tend to remove them to see the actual routes. So at the top Rails generated a single line for us that says resources games. And what this will do is it will actually provide us with the four crowd actions that we talked about earlier, create, read, update and delete. And the convention in Rails is to name your resources in URL so it's actually games and not game. So we're going to do a small change to our routes file before we close it up again. And this change will make the index page for games the default page of our web application. So when you go to the empty URL it will show us the list of our games. And you do this using the route command. So at the top you can write route to and then the controller and the action you want to use as the default route and in this case it's games and index. And after you do this don't forget to save your file especially if you're in nitrous. Ok. Yeah, I realized because I... Sorry? You can define your route to be anything you want basically but in this case we don't have that much to choose from. We only have our game resource right now. So index is a list of all the games that have been played. So there are a number of pre-named actions in the controller and index is one of them. But we'll get to that in just a bit. Ok, I hope that most of you are caught up now and you have gotten the route command into your routes.rb file. So to get a list of all our routes what we can do is in the terminal we can type the rake routes command. So you can go ahead and do that now. So the rake routes command will give you a list that looks something like this. And we can see in the list that routes have been generated for us for the games resource, for all the basic crowd actions. It says URI pattern. You can see the actual URL that our users will enter into the browser to play around with our application. And on the right side you will see controller action and a controller in Rails is just a Ruby class and an action is just a method. And the index action will by default display a list of all our games. The show action will display an individual game. New and create actions gives us a formula controller action to create new games. Edit and update actions is the same thing but for updates. And the destroy action will help us delete our games. And if you look at the top of this file you can see the root path that we added ourselves to the routes file. And the root path right now should be pointing to the index page which would be the list of all games in our application. So we reached a bit of a milestone in our application now that we added our routes and thanks to the Rails scaffold generator we actually have something fairly usable that we can try out. Already in our browser. So to start your server in Nitrous you run the command Rails server dash B followed by 0.0.0.0.0. And to open up the application you go to the menu and under preview you choose 43,000 HTTP. So if you follow this step hopefully your browser will launch. A page that looks something like this. And this is the games index page that was automatically generated for us by Rails. And it provides us with a link to create a new game. You can see here from the list that currently there are no games in our database because we haven't created any yet. But if you click the new game link it actually shows us a form that allows us to create a new game. So we're going to pick a number that is the answer to our game and in this case I'm going to pick 42. And because of the completed attribute that we added it lets us indicate whether it's completed or not but of course we don't want it to be completed yet. So I'm just going to press create game here which will take us to the game show page. So this is the page for the individual instance of a game. This is the first game in our application. And you can see here that the game was successfully created. There's a link to an edit page that allows you to change the settings of your game. And if we look back in the games index page now the game will show up in our list of games. So you can see the number we chose for this game was 42 and it is not yet completed. And it also has links to the other actions. So in terms of crowd this would be read, update and delete. So we can actually also try to delete our game by clicking the destroy link. It will prompt us whether we actually want to destroy this game so I'm going to pick OK. You can see the game was successfully destroyed and our listing of games is now empty again. All these things were actually provided to you by the Rails scaffold generator. And this is one of the powerful things that you can leverage when you start out as a new Rails developer to put a lot of functionality out there without having to write a lot of code yourself. But of course these generators make a lot of assumptions about the code that is generating so it won't give you a very custom solution. In terms of I guess the name of the game obviously it's not really a game yet. It just allows us to start new games. So hopefully by now you will have something working in your browser. To exit the Rails server again you press control C in your terminal. So we have some basic scaffolding in place that allows us to create new games. But we need at least one more resources in order to make it into a functional game. But before we add that resource there is again something important that we need to do. If you verify that your code actually works and tried it out in your browser it is also a good time now to commit your work into version control so that if we add a new resource and we accidentally mess something up we can easily revert back to this working version of our code. Raise your hand until I get it. If you're still having issues with the Wi-Fi please raise your hand and keep it up until Elisha can come over to you and give you the backup Wi-Fi. So it's important to commit our work into version control partly because it gives us a safe point where we can restore our code to a working condition so that we don't end up losing a lot of work because we broke something later down the line. But it also provides us with some history. So when you actually view the commit log you can see the steps that the programmer took to reach the functionality that you have now. If you still don't have Wi-Fi please raise your hand now and Elisha will come over and help you out. So I'm gonna allow for a couple minutes for you all to catch up to this point. If you're already here and you're getting bored then feel free to work ahead in the slides. Thank you. Alright, so we're gonna move on with our work to actually add the other resource we need in our game. So we're building a guess the number game and we now have a game resource but we kind of need another resource to actually complete the game. And the other resource that we need is a guess resource because we need to be able to add guesses to the game. So we're going to generate the guess resource using the race generators but we're going to do it slightly differently this time. We're not going to use the scaffold generator. This is partly because it gives us too much stuff that we won't need and it can't generate nested resources. And it's also going to get familiar with the other generators that are available in race. So we're going to start by generating the model part of the guess resource. And we'll move on to the view and the controller later. A guess resource of course also needs a number. You need to be able to guess a number. And it also needs a reference to the game that we're guessing in. Because we can start several games in our application to be able to have guesses for each of the games so the application doesn't get confused. So we're going to use the model generator. We're going to generate a guess resource. We're going to get a number attribute and a game attribute. So again this all goes on a single line in your tournament. So this time around we're not using the scaffold generator. We're using the model generator and as a result you should only see a few files being created by Rails. It will create a migration file for the database. It will create a model file and it will also create some test files. Now we're going to take a peek into the model file that was generated for us by Rails. So just to clarify this is not a command that you should run. This is a file that you should open in your IDE. And if all went well you should have this file slash models directory. So if you manage to open this file the content is going to look something like this. So thanks to the fact that we told the generator to give us an attribute that references a game the relationship has already been set up from the side of the guess and it is set to belong to a game. If we open up our game model file that was already there generating our first resource its content is going to be empty but in order for the relationship to work we also need to specify the relationship from the perspective of the game. And in the case of our game we want to be able to guess several times in a single game. So we will tell the game model that it has many guesses. The reason that Rails wasn't able to put this in automatically for us is that there is another option that the game could have only one guess. In that case you would use has one guess. But of course Rails can't really know our intention so we need to put this manually into our model file. So once you've added this into your model file make sure that you save the file before you do anything else. And again we've generated a new resource but there is no database table for it yet. We need to run the migration that was generated for us by Rails. So again we do that by running the command rake db migrate. So for now we only have the m part of our MVC we've only generated the model that allows us to represent the idea of a guess in our application. It allows us to store it in the database and we've also expressed the relationship between a guess and a game in that a guess belongs to a game and a game has many guesses. But in order for us to actually do something with this in our application we need to add the other parts of the MVC. So we're going to go ahead and generate a controller and we do this using the controller generator in Rails. And it's a common convention in Rails to name your controllers in plural so it's going to be guesses in this case. And the last create there tells us that we only want to generate the create action because once we've added a guess we don't really want to delete it or edit it afterwards. So running this generator you can see that a different set of files are generated by Rails. It generates a controller file of course. It also inserts a route in our route file. It creates some views for us and it also creates some other stuff like CSS files. So we need to check out the route that was added for us by the generator. So open up the Rails file again. So again this is a file that you need to open in your IDE. It's not a command. And you can see at the top it actually inserted get guesses slash create for us. But we don't really want to use that route partly because it's sort of on its own and we want it to be nested under our game so that we can express that through the URL which game the guess should be added to. And we also want to keep working with this concept of resources. So we're going to change our route file slightly. So we're going to nest the guesses resource under the games resource. We're also going to tell Rails that we only need the create action. So what we're doing here with the keyword only is that we're telling Rails that in terms of crowd create, read, update and delete we only want to be able to create guesses. Again because in our game we don't want to be able to change our guess afterwards and we don't want to be able to delete it once we've made the guess. Faster or slower? No. Yeah I think the break is around there. Should be. So there are quite a lot of colons going in there so try to get them all in the right places. Hopefully our route file looks something like this now. In order to verify that we got it right we're going to run the rake routes command again and hopefully the output looks something like this. You can see now under the route path at the top there's a new route added for us and it's nested under the games URL and it's mapped to the guesses create control reaction. So this is the route that will actually allow us to create new guesses for our game. We're roughly halfway there now with adding our new feature of being able to make guesses to our game. We've added the M and the C part of MVC. We've generated the model and we've generated the controller for our resource but there's still no way for the user to input their guess in the view or in the user interface. So we're going to add in a form and we're going to add this form to the game show page. So you can start by opening up the view file. This is again a file that you need to open in your IDE. And while you're browsing around in the views directory you can see that the generated created a guesses directory but we won't really be using this so feel free to delete that directory from your IDE. So like in all of the coding shows I've prepared some code beforehand that will actually render the form for us. I'm using a real silver method here called 404 which allows us to easily create a form for a singular resource. And in this case we're building an empty guess for our actual game. And we also specify the URL to where the form will be posted and that is simply pointing to the path that we created in our outside. In the form itself it has a hidden guesses guess it has a single input field for the number of the guess and it has a submit button. So in this template you can see all these brackets with percentage signs inside them and this actually contains the Ruby code that will be rendered in our template. Oh no, no, sorry. This is in addition. So you can put this wherever you want in your show file but we don't need to replace the stuff that is already there because it allows us to see whether the game was completed and it also gives us some links to go back. So you put this form wherever you like in your show file. Sorry? Can I add wherever you want in the show file? Okay. Yeah, but I'll do that. This slide just that you don't need to delete the content of that file. Yeah, I should because someone asked me. Say it again now. Yes, because people are still deleting. Alright, so unless you want a page that has only a form in it don't delete the other stuff that is already in there. The reason I didn't include it in this slide is that the code would have been awfully small if I put all of this. So just add this form in among the other content in the show file. Okay. Do you want to finish your last sentence? I have no more sentence for this slide. Okay. Alright, so I have orders from Elisha that we're supposed to take a break now. So use this break to catch up. Okay, bye. Okay, let me introduce you to my team. So if... If Sophia is seeing Ken, I don't know if you can see her so she has been checking all of you in so she's also helping out with the organising of stuff. And today is a very special day because today is her birthday. Camera is here also. Camera is here? Oh, one is already up. Okay, since you can do your break announcement and also tell us a bit about yourself. Yeah. As you can see, I'm going to tell them this. To go in available. You don't need to say a wish. Okay, blow. For you, but... A lot of bananas and stuff right at the back. So we will have... I hope most of you had a chance during the break to catch up with the workshop so that you're all at or near this slide. So now we've created our forum for creating guesses for our game. And we have means for users to input their guesses. But we're not yet doing anything with the guesses that the user inputs. So if you remember, the controller is like the glue that connects the view that we just created with the model that we created using the generator earlier. So we're going to open up this file. Again, this is a file that you need to open. The guesses controller, which is located in your controllers directory. And if you open this file right now, the only thing you should see is an empty create action. And the first thing we need to do is to allow the parameters that we need to be passed in. The reason you need to do this is because of a security feature in Rails called strong parameters. So basically anything passed by the user that we have not pre-approved will not come through to the controller. So we're going to do this by creating a private method called guess params. And we're telling this method that in order for the params to go through to the controller, it's required that the params has a guess key and we will only permit the number attribute from the form. The reason for this is that in creating web applications you should never trust user inputs because a user could easily manipulate what is sent to our application. So by doing this we're explicit about the things that we expect to come through. This can be a common source of issues when you're just talking out with Rails. So it is recommended that you go and read up about strong parameters in your free time. But for now just take note of how we are actually whitelisting the attributes that we want into our application. The next thing we need to do is we need to define the game that we're adding a guess for. And we're going to do this using what's called a before action callback. And as the name implies, it is an action that is run before, a method that is run before the action. We're going to call this action set game and we're going to use the game ID parameter that is passed from our view to find the game in our list of games. This is important because we need to know for which game the user is submitting a guess. If you've been to the previous workshops you'll also notice that we're storing the game in an instance variable called atGame. And this will make the variable available to all the other methods in our controller. So by doing this we've accomplished two things now. We have explicitly stated our expectations about what the user will pass us. We're expecting them to pass us a guess that has only a number in it. We've also found a game for which the user is guessing and make the game available through the instance variable atGame. Next I'm going to show you what goes in the actual create action. And the next slide won't have any of the other controller code but hopefully it's there already in your application. So finally we can tell our create action to create a new guess inside our game. And thanks to the set game before action we now hopefully have a game available to us in the atGame instance variable. So we tell this action that for this game's guesses we want to create a new guess. And you can see the argument guessparams. This is actually a call to the method that you define for the strong parameters. And by using the create method with a bang this will actually generate an error if there were any problems with creating the guess. Finally within the create action we want to redirect it back to the game show page and we want to give the user an indication that their guess was accepted. So in this case we'll just show them a missing good guess. Once you've done putting all this code inside your controller file don't forget to save the file. And we're going to test this out and hopefully we'll have some functionality that allows us to add new guesses. On your server in Nitrous use the command res server dash b followed by the four zeros and you go to the preview menu to open up your browser. In case that your Nitrous account timed out during the break you might need to go into the right directory again which is the code slash example directory. I'm going to start a new game in my application here so we can test out the guessing functionality. So if you've got your form rights in your new templates you will have something that looks pretty much like this. It has the label guess a number input field where you can put your guess and a button that says create guess. So I'm going to try this out by putting a random number and you can see that the application tells us good guess which is what we specified in the controller but you can see that this game is also not very smart yet because even if I put the correct guess the game would still just tell me good guess so it's not quite a game yet because we didn't put the actual game logic in. The correct guess is when I created the game I specified the number that I wanted to be the secret number. Can you just start your server Create a new game Not in the actual code when you go into your application So to clarify the number that you input when you create a new game will be the correct answer to this particular instance of the game. I think by now some of you might be experiencing some errors I'm going to give you a chance to catch up with the coaches roaming around and I'm going to give you a chance to see if you can get the correct answer to this particular instance of the game. A chance to catch up with the coaches roaming around. We're going to use that to indicate whether the game is finished or not. So you can see the label is completed so eventually when you guess the correct number the game will be considered completed. Another question I just got is what does the polls mean here? So we're going to use this flag to indicate that the game is finished once we have the game logic in. So as soon as you have guessed the correct number the game will be considered completed. So there's a pile of something. Do you find this? Yeah, it's a bit of a coin here. So I'm going to use this to indicate that the game is finished once we have the game logic in. So you see this is the correct answer to this question. I'm going to give you a chance to see if you can get the correct answer to this particular instance. Let's go. This is where the Wii directs that because after the King Wii directs the controller they're not sure what's the expected outcome that they're supposed to see. Did you bring it through the process again? Yeah, sure. Right, so I'm going to show you again what the redirect part of the code actually does. So I bring up my application again and I'm going to pick one of my games. I'm going to pick the first game. I'm going to go to the show page which is the page where we put the form. So when I input a guess here and I click the create guess button it is going to send this guess with this number to the create action in the guesses controller. And if you remember at the bottom of the create action we told it to redirect us back to the show page and flash a notice to the user. So when I click this button you're not going to see in the browser the request going to the create action. It will just immediately redirect you back to the show page and it will flash the notice that you told it to do in the create action. If we did not specify this redirect at the bottom of the create action Rails would try to take some default action which is usually to render the show page of the resource that we created. But because we don't have a show page for guesses we can't really use that behavior. Oh, by now you have weeded out most of your errors and before we continue once you verify that your code is actually working we're going to create a new milestone in Git so that our hard work is not lost in case we make any mistakes down the line. So to exit your server you press control C and once you're back in the terminal you need to add all your files to the Git staging area and once you've done that it commits all your changes with a meaningful commit message and once you've done this you're somewhat safe because you won't lose any of the progress that you made this far. So we've gotten pretty far already but we're missing one critical piece of functionality for our game to be an actual game and that is it doesn't tell us whether the guess we made was the correct guess or not. It will just tell us that it was a good guess. So we're going to go ahead and implement the actual game logic for the guess a number game and we're going to keep working in the guess as controller file so unless you kept it open you need to open that up again. So inside our create action we're going to check if the guess number was the actual number of the game that we were playing and if it is we're going to update the game and set the completed attribute to true we're going to redirect back to the game path again but we're going to change the message to tell the user that they won the game. If their guess is not the secret number of the game we're just going to redirect them back and prompt them to try again. So if you were into the previous workshops you might recognize some of this logic from the exercises done there. So on the first line in our create action now we're actually storing the guess we just created into a local variable so that we compare its number to the number of the game. Also be careful when you do the comparison and note that you need to do two equal signs because if you only use one it will be an assignment and it will always be true which is not how we want our game to behave. Adding this if statement to our create action we allow our code to know the difference between a correct guess and an incorrect guess and we'll make it take the appropriate action for which every case is true. We instead are copy pasting the code so in every code that you show tell them what page that is like is this one file or is this in the terminal Do they key this in the terminal or what file do they key this in so be more explicit in where you are So do a quick check on how many people got understood what they are doing here. Can we do a quick show of hands which ones of you are uncertain about what's going on in this piece of code? Usually the point that you need to like guess is So if you're not quite sure what's going on please raise your hand and the assistant coaches will help you out. So essentially what we're doing here is we're comparing the number of the guess that the user just made from the form in our show page to the correct answer that we specified when we created the game. If the user made the correct guess we're going to update the game itself to say that it is now completed. After that we're going to redirect back to the game's show page we're going to show the user a notice that they made the correct guess and they have now won the game. The other case is if the number is different from the correct answer we will enter into the else statement and the only thing we'll do is we'll redirect back to the game's show page and we'll flash another notice to the user to prompt them to try the game again. So we're going to try this code that we just wrote out in our browser. Hopefully you remember how to start the server by now so it's redserver-b 00000 I have now started my server again I'm going to test out the code that we just wrote so I'm going to pick the first game in our database I'm going to go to the show page and we can see that the form that we created earlier is still here the difference now is that our application should be able to differentiate between a correct guess which in this case will be 42 and any other guess So I'm going to start by entering an incorrect guess and see what the response is in our application So I'm going to guess the number 13 which is clearly wrong because the correct answer to this game is 42 Once I press the create guess button the game will tell me that no this was not the correct guess try again so we know for sure that our game will recognize when the guess is incorrect Now we're going to test out to see if it recognizes that the correct guess is actually correct So I'm going to input 42 into the guess which is the actual answer for this game and hopefully the game will recognize this as a correct guess and you can see here in our application it recognizes this as a correct guess So for one it displays a different notice it displays correct you win and it also sends the completed flag to true here which is what we did in the first line of our if statement we told the game to update it's completed actually to true in the case of a correct guess and you will also be able to see this if you go back to the index page with the list of our games you can see that this game is now completed So after you added this if statement to your controller action fire up your server and see that it's actually working and if it's not working or you're getting errors then just raise your hand and the instructors will come around and help you out and in the case that you don't have an actual game to submit your guess in just use the new game link to create a new game in your database very interesting Hey hopefully at least a few of you have a fully functional guess the number game by now obviously it's not quite the next candy crush at least not yet but we're going to improve the game a little bit to make it a bit better and the way we're going to do that is firstly we're going to check in the work that we've already done so that we don't accidentally make a mistake and then we lose all the work with the game logic here so to exit your real server you press control C again you add all your changes to the git staging area and you commit it using a meaningful commit message back to our game first issue with our game in the current state is that the game is not that hard because the secret number we're supposed to guess is displayed in the game showcase which kind of detracts a bit from the the actual game so we're going to make it so that the secret number is only shown once the game is completed and at the same time we're only going to show the form that less the users submit guesses show only when the game is not completed so the file we're going to be working with now is again the show template that is located in the views slash games directory so this is the file you need to open in your IDE it is not a command here on it is the file that you need to open so to this file we need to add another if as statement it makes it so that when the game is completed we will not print when the game is completed we will print out the secret number but if it's not completed we will instead print out the form so first you need to locate the form that we added earlier it is this call here starting at the line form and to this file we're going to add an if statement inside the template that checks whether the game is completed if the game is completed we shall display the secret number for the game and this call here inside the if statement is already available somewhere in your template so the parts you need to add to your template are firstly the if statement secondly the else statement and you need to finish it all off with an end once we have that we put the code that is already there for displaying the number inside the if statement and we put our form inside the else statement for the parts of the templates that show if the game is completed or not and the buttons you can just leave them as they are so depending on how your template file is laid out right now you might need to reorganize the different paragraphs of it anything that is placed between the first if statement and the else statement will only be rendered if the game is completed every place after the else statement and before the final end statement will be rendered if the if statement is false and again you might have some template code before this code and also after it and that is fine in addition to this enhancement to our game show page on the same page we are going to add a counter that keeps track of how many guesses have been made for this particular game so the code required to do that is not very long you can place this anywhere you want inside your show template file additional information is very similar to the paragraphs that are already in the templates and we are using the count method that is made available to us by Rails to get a count of the number of guesses for this particular game again you can place this code wherever you want within the template we are going to test out the changes we just made to the template so firstly fire up your Rails servers and open up the page again in your browser again the changes we just made were made to the game show page so I am going to pick the second game the first game in my list here that is not yet completed and I am going to go to its show page you can see now from this show page that the answer for this game is no longer displayed because the game is not yet completed you can also see that we haven't made any guesses for this game just yet so I am going to go ahead and make an incorrect guess in order to see if this counter actually works so the correct guess for this game is the number 13 so I am going to go with another number I am going to create this guess and just like before the page is going to tell us that no this is not the right answer the game is still not completed and the number of guesses we have made for this game is now 1 so I am going to go with another incorrect guess we get the same result and the counter of the number of guesses has now increased to 2 I am going to give the correct answer for this game once I press create guess button like before the game tells us that the answer was correct and that we will the game is now completed it took us 3 guesses to win this game now the game shows us the correct answer because we already won the game and it no longer shows us the form that allows us to submit new guesses I am going to create a new game just to walk through it all again I am going to choose a number that is the correct answer for this game I am going to create the game we immediately take into the show page we can see that this game is not completed and no guesses have been made but the form is there to make new guesses I make an incorrect guess it still works the same that it worked for the first game I make the correct guess the game is completed we can no longer enter new guesses and the answer is displayed inside the game our game is starting to shape up really nicely but it is still not perfect there are still some issues that need to be ironed out we are going to do that by adding some finishing touches to our game one of the shortcomings of our game right now is that we can submit a guess without actually providing a number and it doesn't really make much sense in a guess the number game that we can guess without guessing a number so we are going to add some validations to make sure that the number is always provided so as we mentioned earlier validations are handled by Rails models but we also have a separate set of validations in our database that are called database constraints and it's normally a very good idea to have the validations in your models match your database constraints so we are actually going to try to edit our migration files to add some database constraints but because we already migrated our database using our existing migration files we first need to roll back all the changes to our database and to do this we are going to use the rate db rollback command in our terminal we are going to give it a step of 2 which means that it will roll back the last 2 migrations and in our case we only have 2 migrations in our application so this will reset our database to the state it was in before we did any changes to it so you first use ctrl c to exit your database server and then enter this command into your terminal the reason we need to do this is because we already ran our 2 migrations Rails will never run them again even if we edit the content inside our migrations so we first need to roll them back before we can migrate them again so we are going to edit our 2 migration files in order to do this you need to open the db slash migrate directory in your editor so this is the folder where all your migrations are located so inside your db slash migrate directory there should hopefully be 2 files and the file name should be a timestamp followed by the name of the migration in our case there should be create games and create guesses we are going to open up the first migration file in our editor and it's going to look something like this on the inside this is the ruby code that creates the games table inside our database because we want the number to always be there we are going to add a constraint to the number column which is on this line that says t.integer number to this line we are going to append null colon false and by doing this we are telling our database that we will never ever allow this value to be null or in other words we cannot create a game without also specifying a great answer for that game and while we are inside this file we will also apply the same treatment to the completed column where the completed attribute of the game model we don't want it to be able to be null we want it to always be true or false and when we create a game we want it to default to false because we don't want the game to be completed as soon as we create it when doing this you need to be somewhat mindful where you put the columns inside your code while we are in this db migrate directory in our application we are going to open up the other file which is create guesses and we are going to do the exact same thing to the number attributes that we did to the game by appending null colon false in the end we are telling the database that we cannot submit a guess and store it in the database without also providing the number that we want to guess once you have made these additions to your migration files firstly don't forget to save the files and after that we can try running our migrations again and with a little luck this will work if you end up with an error when you do this go back to your file and check that you have all the commas and the columns in the right places we have made some changes to our database constraint by editing our migration files and rerunning our migrations now we are going to add the validations into our model files so you can start by firing up the file in your editor by going to the app slash models directory and finding the game.rb file in there so this is the file you need to edit to add a validation to the game model we are going to validate one single thing in our game model we are going to validate the number attributes we are going to ensure that it is there by specifying presence colon true and we are going to validate that it is a number by doing numericality colon true the way this syntax works in Rails is you start specifying a validation with the keyword validates you pass the name of the attributes that you want to add your validations to in our case it is a number attribute following this you add any number of validations you want to add to this attribute in our case we added the presence validation which checks if there is a value provided for the number in the first place we also added the numericality validation the checks that the user didn't send in a stream or something else but an actual number we are going to also add some validations to our guest model which is located just next to the game model in the app slash models directory and if you go in and fire up that file these are the validations that we need to add we are going to add two validations to the guest model firstly we are going to validate that the game is always present so we don't ever want to have a guest that doesn't belong to any of the games so we are going to add a validation for the game attributes and validate that it is present we are also going to use the exact same validation that we did for game in that we validate the number provided is present and there is a number which is by doing this we ensure that when a user guesses a number if they did not provide a number at all or if they provided something else like a stream we can present a proper error message to them which we will see soon so we are going to test out our validations in our application to get you an idea of what it looks like inside the actual application so you can go ahead and fire up your real servers again if you are getting an error now trying to run your server so that you forgot to run your migrations again after you edited them and Rails will give you an ending migrations error so we are going to test out our validations by trying to create a new game and if you remember from the changes we just did we stated that a new game must always have a number provided and the number itself cannot be a stream or something else so I am going to try to create a new game and not provide a number for it and you can see that the Rails scaffolding provides us with some facilities to display error messages to the user without us having to do anything but add a validation to our model so in this case I didn't provide any number so Rails decided to show me an error message that two errors prevented me from saving this game and the first is we add a validation to number that it has to be present and it's telling us that here by saying that number can't be blank we also added the validation that number must be a numerical value but because nothing was provided at all it also says that the value that we passed was not a number where is Elisha hmm Elisha is away I don't know, maybe she went to the washroom or something just go on you need anything? I did not prove Elisha had a question he texted her just drag her out of the washroom so in my do you want to drink? in my slides I have a lot of suggestions for how to enhance this guess the word nothing nothing to do as extracurricular activity would we be willing to accept a very advanced version of this technical test I'm trying to get out of the wall to see that you currently confused if you already confused already do something simple and do it well so many let me just get a few this is the conscience if not just skip skip on this advancement and then just go through the entire app process at least they know something but they can create something Elisha we need your github I can't use mine because I use one password yeah it's already password third what do you need from me I need your github account so I can show them how to push through you just have a sec yeah I checked in 3 cultures they don't really think that they are either not following anymore or in law they are doing stuff but don't see the big picture so let's quick the advanced part and we can start from creating the app from scratch then try and tie in where do you do your front end where is the CSS file they should know where the CSS file is but just tell them who is the CSS file will be a concept for the events, block and also travel app with concept use today okay so let's take the last remaining time to do that okay and I will push it to github and doku yeah can you create oh you just create a party we go so everyone can just like thank you you need any coffee alright this last addition of the validation actually concludes all the rinse work that we are going to be doing in the workshop today so we are going to take the last sliver of time today to walk you through sort of the entire workflow that you need to go through with the technical test so obviously this will be a very shortened down version but we will show you the steps from creating a new project making some changes pushing your code to github and also deploying it to oroku I think I am going to need to mirror the display to see what I am doing there we don't have any secrets here I will do the thing then hello so a lot of you have some questions on how do we take the stuff that we are learning in three workshops to create an application for a technical test so we are going to take the rest of the time for this workshop to put all the theories that you have learned and Ted is going to bring in a process of how do you create an application how does all the theories that you have learned put together into an application and push it to github and you so yeah so yeah I mentioned for this one it's still not to be up why don't you just use sublime because I don't use sublime it's going to be very weird probably I don't want to point this sublime so we are going to build a very simple block from 0 to 1 in a very short amount of time so I need your attention now to be able to see the steps you need to take to complete the technical test which is the entry requirement for the new camp so we are going to build a Rails app so the first thing we need to do is to create a Rails project and the way you do this in your terminal is by using the Rails new command I'm going to name my project blog and there are a bunch of options you can provide but for the purpose of the technical task you can just go with the defaults so Rails is going to create all the scaffolding and all the files it needs and it's also going to run bundle install which usually takes a minute or two so I'm actually reusing my nitrous container now but if you plan to use nitrous for your technical task then it's probably better if you create a new Rails project so you don't mix it up with your number again the reason this bundle install takes so long is it's actually downloading all the third-party libraries that Rails depends on should have some elevator music you know everything we say is going to trickle it alright, still bundling I wonder if everyone did this right now I think if everyone just did Rails new at the same time now this might take a while because we're all on the same wifi ok so while we're doing this I'm actually going to cut over to github to just create the new repository that we're going to use to store our code so I'm logged into Elisha's github account now we're going to click the new repository in the upper right hand corner I'm going to name my repo just blog I'm going to give it a short description I'm going to indicate that I want to make this a public repository this is important partly because private repositories are paid and also for us to be able to review your code for the technical task the repository needs to be public I'm going to ignore the other options to create repository it seems like while we were setting up the repository in github we actually finished bundling our new blog application so next to our sample application we now have a blog application so I'm going to start by changing to the right directory now the first thing I need to do with a new application is to git init this tells git that we want to create a new git repository to store our code and you can also see from the terminal that as soon as we are done git init it will create an additional piece of text in the prompt that tells us which branch we're in we're going to add all the changes or all the changes that Rails have added to our new project by doing git add we're going to commit all the changes with a message from initial commit you just realize this is not going to work because your git user is not set up in the nitrous probably in your account and even my user is not set up in here even my user is not set up in here so you should just set it up in my account you should just set it up because I don't have my account here in your box I just need to remember how to do it yeah that's just adding the remotes but your user the actual certificate I don't even remember how to do that because it was so long since I did do you just want to go the wrong way yeah yeah you have to go the wrong way so we've actually committed all the stuff that was created by Rails the next thing we're going to do is we're going to add some scaffolding for a blog post in our application so this is what we walked through earlier during the workshop I'm going to use the Rails generate scaffold command for now I'm just going to give the post two attributes one is the title of the post and the other is the actual content so I'm going to go ahead and run this generator right it looks like Rails created quite a bit of stuff for us it's just the name so post in this case is just the name I chose for the resource because our blog name is Postfrag so we're going to commit this resource into version control another useful command to use is git status which allows you to see all the unstage changes that you have so we're going to do the same thing that we did for the initial commits we're going to add everything we're going to commit this with a meaningful commit message in fact before we do that there's one step that I forgot to do which is to migrate our database I need to migrate my database before I commit the changes to version control is that every time you run a migration Rails will update what I call the schema and if I migrated my database after I committed the changes then there would be one uncommitted change in the schema we added a post resource to our application so we can just do a quick sanity check to see that there's actually something in our application so this is the default root page in Rails in this case we didn't add a root path to our application so it's going to look like this but we should be able to visit our posts page and it looks similar to our games index page for the yes number app and we can hopefully add new posts here so we have something like an extremely primitive look already with just one line of code from our terminal I'm going to go ahead and exit the server by pressing control C you can use the command git log to see a list of the commits we've done already so we can for the purpose of this exercise we can say that we're pretty much done with our log the next thing we want to do is to get our log on to GitHub so GitHub actually provides you with some instructions here that you can use so we need to add the remotes for the repository that we set up in GitHub and to do that you can copy the URL that is given to you at the top in our terminal we use the command git remote add to add a new remote you can name these remotes anything you want the default name is origin but I like to name it GitHub to make it more explicit after that you need to paste the URL that you just got out of GitHub the next step of getting your code into GitHub would be to push the code to the remotes that we just created I'm going to try that now and I'm pretty sure that it's going to fail but let's see using the git push command I give it the name of the remotes that we just added and I give it the name or the branch git push to GitHub so it's asking me if I want to add these new hosts and just go ahead and say yes so as we expected this didn't really work because we don't have access to the repository and the reason is that this nitrous account doesn't have a licious git user set up so we're going to try to set that up now unfortunately because it's like two years I did it the last time I'm going to have to google the actual steps so it looks like unfortunately nitrous provides us with some neat interface here it's telling me to go to the account settings page and select connect with github so I find the account settings by clicking my portrait in the upper right so down here under github it's asking me to connect with github to my keys so it seems I was redirected to the landing page which hopefully is an indication that it actually worked so you can see we are now connected to github with Elisha's account so we're going to go back into our application your application you will not be in the actual project directory so the first thing you need to do is to get in there so let's check our github we've already committed this build there so we're going to try to push it again to github hopefully this time it will work so again we're going to use the git push command we're going to tell it to push to github which is the name of the remote we added and we're going to tell it to push the master branch and unfortunately it's still telling us permission denied we have the project now we're going to go to the projects we have the project address settings we have the key in this case okay so we're going to add it on the project level okay so I just got some tips passed to me here that I actually in the dashboard also need to go under the project settings and manage my SSH keys so you can see here my public key for this container and nitrous provided us with a neat add to github button so we don't even need to copy paste it into our github account we're going to give it a third try and hopefully now we'll get another result so you can see that we no longer get permission denied it is writing 102 objects to github and it created the master branch on our github account so we're going to have a look inside if I can find it so if we go back to our repository we can now see that all the code that we added in our nitrous account has now been pushed to github we can see we created our projects 14 minutes ago and we added a post resource 9 minutes ago so all the code we just wrote is now hosted on github and this is what we want to do for the technical task so that we can actually go in and have a look at your code so the next thing we're going to do is we're going to deploy our application to Heroku to make it live on the internet so I'm signing into the Heroku dashboard from Heroku.com I'm going to use the new button in the upper right and I'm going to choose create new app I need to provide an app name this name needs to be unique to Heroku so it's possible that a lot of names are already taken so I'm going to name it takeLadies-blog and that's the only thing required for you to set up the apps I'm going to click the create app button Heroku has now set up an application container for us this allows us to push our code to Heroku and make it live on the internet and the method we're going to use is we're going to push the code using gith Heroku remote so let's see if in nitrous we actually have the Heroku tool belt installed already so it seems like nitrous conveniently provided us already with the Heroku tool belt if you're not using nitrous you might need to install this manually and to log in you just use Heroku log in I'm going to add my Heroku account the next thing we need to do is we need to add a new gith remote for our Heroku application and the command for this is because you need to use the Heroku tool belt to set it up but this command is also available from the Heroku dashboard so you can just copy and paste it into your terminal so it's telling us now it has added another gith remote called Heroku and if you want to view a list of the remotes you already have you can use the command githremotes dash b so in our case we just used the githremotes that we set up earlier and now we also have a new remotes called Heroku and the next thing we're going to do is we're going to push the code we just created to our Heroku application and the way you do that is the same way that you push code to any other githremote including github so in this case we do gith push again but instead of pushing to github we push to Heroku we push the master branch and Heroku provides us with some status updating us with everything it is doing to set up our ruby on rails server you can see it's currently doing bundle install and it looks like our push was rejected and the reason for that is that Heroku does not support SQLite so we need to pick another database again to do that we need to go into our gem file we need to change the line that says gem sqlite3 to pg we'll use the version 0.18 I'm going to save this file I'm going to bundle it again so the reason we need to do this is there are several different databases to choose from sqlite is the default database that rails will install for you when you create a new rails app but sqlite is not supported on Heroku Heroku by default supports Postgres which is shortened to pg in the gem name while we're here there's also another gem that is required by Heroku to run your application we're going to add it in here the gem is called rails12factor so the gem name is rails underscore 12factor so we're once again going to bundle our application because we have done some changes in our gem file we need to commit those changes to version control so once again we're going to add the files to git and we're going to commit them so I'm giving it a commit message of change database gem to pg and add 12factor so once again we've created our changes let's try to push to Heroku again it looks like this time the deployment to Heroku was successful so we're going to see if we can open our application which should not work so we just use the open app button in the top right of the Heroku dashboard it's giving us an error page and the reason for this is that we have not migrated our database on the Heroku server so if you remember the way we managed the database in rails is through migration files and we have not yet run those files on our Heroku server so we're going to run those now the way you run commands on Heroku is by using the Heroku tool belt and we're going to say Heroku run in this case so we use the same rate we see the migrate command that we otherwise would but prefix with Heroku run you can see that it is giving us the outputs of running these migrations back in the terminal and there's no rollback in there which means that it should be successful once again we're going to go to the Heroku dashboard and in the top right we're going to click open app and there's still something wrong in there so we're going to go check the lockpads from Heroku it's a routing error you don't have a route wait should show me the default page right? or not when running in production no because it doesn't have the index file I think it doesn't display it oh it doesn't I think so I'm not 100% sure but that's the error so Greg has a theory here that that's my error 100% on Heroku we don't actually get the default landing page of rails so let's have a look to see if our posts are actually in there so it was actually working all along only that because we didn't add the routes routes like we did in our just the number app when Heroku tries to go to the routes URL it doesn't find anything and it gives us an error so you can see they are very primitive app that is hosted on techladies-blog.herokuapp.com slash posts so anyone can now theoretically go and check this out and anyone can add posts as well which is not ideal for a blog application but in order to keep the time down we didn't add any application to the application so we now also have our first blog post on our techladies-blog and that is essentially all the steps you need to take to get an application from your terminal to live on the internet how many of you are very lost? which part are you lost? don't say anything change the database change the database do you need any going to label? so the things that there are different databases types that are available so her question is why do you need to change database and what is that pg, sql, like thing about right so the thing about Heroku that is it does not play well with any database except for postgres it's called eos, e, g, r, e, s so that's why we need to get rid of the sql, like jam and replace it with a pg jam so with that then you can just deploy it very easily so every time if you want to make changes to the database jam you have to make db, mic, bandaid right? bundle install when you change your jam file in mic install it make sure that the computer is getting all the jams that you need to play on app so who else was right so can you see how the theory of the three workshops are actually coming together because when you create a table you talk about different data types like this is a string, this is a text, this is an integer and on a second class you learn about what is front end of which if you want to change the css of your app on nitrious you locate your css file assets this one? so you will do it here so does it make a difference if it's post or scaffold scss if you want to change the look of your posts page specifically you go into the posts.scss file the scaffold will apply to all your scaffolded pages so if you only want to change the look of the post resource you go to that post scss if you want to change the look of everything else you go for the scaffold scss so this is where you do the front end workshop stuff we have learned we put it in either the resource or the entire scaffold itself here so so that's the first two workshops and in this workshop we learn about rails we learn about the MVC model view and controller and how you can easily use this to create an application by running the rails generate scaffold so if you remember the command it was rails it's telling like okay I want these rails and they are rails generate being a scaffold calling and I would call this resource uncertainty so it could be post, it could be blog anything you want so the thing how you take a good name is take by being a name that makes sense when you try to read your code again so don't have like some magical number you can do that but you'll be really confused on what it's about so rails generate scaffold posts and thereafter it's your data types what do you want to call a column name and what is this data type about so once you run this this command and then you do a rating in my brand then you have an application which looks like this so any other questions? who else is still very lost? now it's a time to ask because this is the end of the three workshops before the technical test so any questions with regards to how you how should you think about the app that you want to do? Amanda had a question on when do I use when do I put it in post and when do I use it in scaffold so you use it in post or resource specific if it's only for that resource so that means your index file your new file your show file under the post SCSS and if it's going to be across all the resources so the posts command resource then you put it in the scaffold SCSS but actually it's not a hard part to write so you just put it anywhere is it? yeah alright so the files are only going to organize SCSS all of the files will actually be included in the actual file that is included on every page but it can be a good idea to organize SCSS I think per controller is what they are saying here in the comments oh yeah per controller which is your resource but at the end of the day it doesn't matter so it's not the end of the day it's not like a really big problem if you put it in the wrong SCSS as long as it is in one of the SCSS make sure that your class names match of course okay who else have some questions? in terms of file yeah so the question is for the technical test can we use Ruby instead of Rails? yes we can if you want to do another guest number similar type of game then you want to be more comfortable with Ruby because what Rails does is it's a free content list of formulas recipes that you can easily use so it can be a bit too bloated for your usage so it really depends on why you want to do it if you want to do like a magic game a type of random thing you can do something like random movies or vice-versa any other questions? anyone? who else is really lost and you will have lost yeah so we don't really dictate that you use Rails for the technical test but it can be good to remember that all the projects we will be doing in the bootcamp will be running on Rails so you can sort of delay the pain a little bit and it's normal to be very overwhelmed with Rails because with just the sheer scale of it there are so many things and concepts in there but really the only way to get over it is to get some mileage and build some applications with Rails until you wrap your head around it which can honestly take a bit of time I think for me it took at least a couple of months of working full time with Rails before I felt comfortable with all the parts of the application okay so I guess like I think it's really good to explore how you should think about your app for me what works is I start thinking in tables for example in this post table what columns do I want and what layout types are they before I start running so if you look at the suggested ideas go back to my slides to do this let's take this for example so so let's think about tables okay so this will be a table for articles what's going to be in this table it should be a country name because it's a country name so it will be a what type it will be a shame to try and then the next thing will be a trip description which we're probably going to spell on the itinerary so what are the types that are going to be yeah you can do a shake or you can do a text if you have a lot of this there and then next is travel dates so I guess this is a daytime date date or daytime depending how specific you want to be so for this data type the travel dates, the data type or daytime depending on how trip you want to be okay and I guess the last trickier part is the photo so you don't have to you don't have to care about uploading photos for this for this ad so what we're going to do is we're going to cheat it for you so for the photo you can just upload the URL and just have it show the image using the URL so you don't have to care about uploading it as long as the image is already on the internet there is a URL that locates that image and you can just create a field that shows you that pulls the image using the image of the URL so you use that by an image tag it's with a source attribute SRC attribute so in that case what is the data type of the photo should be it's supposed to be a jpeg but since it's a URL so it can be a string so photo photo is a string data type okay so now you know of that for this ad there is one resource called articles and in the articles there is a name description, travel dates, and a photo of which photo is a string because I'm talking about an ad you can see if you show the articles of a country this is the show page so the specific now this is the show page and then when there should be a page showing all the articles this is the index page of the Rails app okay some ideas some ideas of relevant now should we do another example okay this is easy let's go to the third one okay now this is the event right ad so again let's do this again so how should we take it in terms of tables so in this table one of the tables I want is called events and in the events table what column should we add in the title what kind of data actually this data page should be a string and then next we're going to have description of this description assuming that it's a long write up so what data page actually this data page should be a text so picture what data page actually should be a string and a date is of course a date at the same time so user can add events so that is your events new page because it's a form where you can add all the stuff that you need and of course it should also be a show with all the data that you have created and then the next part of the app is have an events listing page and this will be your index page okay get a hang of it get a hang of it okay let's just do the second one anyway okay maybe I should stand here um okay this all of you should be expert for this one because that's sort of like what we went through so again we will have a blog post so what should what columns should that be in the post table hi yes the title is one and what data type should the title be okay so what else what other than title which is a string what else should be in the blog so in the blog post there should also be a content column and that data type is a text your new page and also a show page that shows you what blog article you have created and then there's also a home page which essentially is your index page this one if it's too difficult in the straight way it doesn't matter okay that's lost now I'll just develop okay okay okay does anyone have any other questions wrap up the entire free book camp workshop series I hope you had a lot of fun learning and feel confused which is probably because of learning new things you know everything is overwhelming this doesn't it's increased like English but not English I got what I'm doing so it's perfect it's perfect in common that is why we also have a community that helps you just post on the group and if no one reply I will grab someone to reply for you okay so I'll be sending out a survey just to not really understand how we can do workshops better you should receive it in about an hour so we have this space until we get picked up which I don't know what time is it but it's probably a day so just feel free to stay back if you want to have all of the coaches help to help you think through how you want to create the idea that you want to do okay thank you so much you deserve a round of applause for yourself please did I rescue you did I rescue you did I rescue you did I rescue you did I rescue you I couldn't stop talking let's cook let's cook the stuff oh yeah I'm very hungry I'm not joining