1 00:00:00,000 --> 00:00:05,000 [Master Class] [Designer and Developer Workflow] [Generating the Scaffold] 2 00:00:05,000 --> 00:00:07,000 So, up to this point, we've generated a new Rails project. 3 00:00:07,000 --> 00:00:11,000 We haven't really done anything with it, but we've created the skeleton for it, 4 00:00:11,000 --> 00:00:16,000 and we've set up our GitHub account and sent the details over to Nick. 5 00:00:16,000 --> 00:00:21,000 So hopefully by now, he can at least pull the project and set up the basic Rails stuff. 6 00:00:21,000 --> 00:00:26,000 And our next step is to go ahead and configure it and see if we can get it up and running. 7 00:00:26,000 --> 00:00:28,000 Now, I just got a message from Nick. 8 00:00:28,000 --> 00:00:31,000 Let's go ahead and take a look. 9 00:00:31,000 --> 00:00:36,000 "Hey Jim, I was wireframing the show view for the jobs...and I was thinking 10 00:00:36,000 --> 00:00:39,000 that there were a few fields that we could add." 11 00:00:39,000 --> 00:00:43,000 "I know we originally agreed on just having a job title and description for the job." 12 00:00:43,000 --> 00:00:47,000 "But I think it would also be nice to add the name of the company 13 00:00:47,000 --> 00:00:52,000 and a details link in case the company wants to include an external link 14 00:00:52,000 --> 00:00:56,000 so they can see more details about the job." 15 00:00:56,000 --> 00:01:04,000 Okay, so it looks like we've gone from having our job just be a title and description 16 00:01:04,000 --> 00:01:10,000 to now having a company name and a details link. 17 00:01:10,000 --> 00:01:13,000 That looks like a pretty easy change, but I'm glad Nick went ahead and sent that 18 00:01:13,000 --> 00:01:16,000 as soon as he did so I don't have to change an existing model 19 00:01:16,000 --> 00:01:20,000 because I was just about to do that, so the timing is perfect. 20 00:01:20,000 --> 00:01:22,000 So, let's add that. 21 00:01:22,000 --> 00:01:25,000 All right, so let me just go ahead and reply to him. 22 00:01:25,000 --> 00:01:27,000 "Hey Nick, that all sounds pretty good." 23 00:01:27,000 --> 00:01:31,000 "I'll go ahead and add those, and I'll let you know exactly what the different fields are 24 00:01:31,000 --> 00:01:34,000 when I go ahead and generate it." 25 00:01:34,000 --> 00:01:40,000 "Give me a few minutes and I'll go ahead and push the scaffold up with these details." 26 00:01:40,000 --> 00:01:43,000 So now, let's go ahead and do what we promised to do. 27 00:01:43,000 --> 00:01:49,000 Before we can scaffold anything, let's go ahead and see if our Rails application is even running. 28 00:01:49,000 --> 00:01:56,000 So, the first thing I want to do is run bundle install. 29 00:02:09,000 --> 00:02:12,000 So now, we've run bundle and it's gone ahead and installed all the dependencies 30 00:02:12,000 --> 00:02:15,000 that are needed to run this application. 31 00:02:15,000 --> 00:02:17,000 Let's start up our server and see if it works. 32 00:02:17,000 --> 00:02:28,000 So, we'll type in "rails server" or just "rails s," and let's go over to our browser. 33 00:02:28,000 --> 00:02:32,000 And if we load up local host 3000, we can see the Rails welcome screen. 34 00:02:32,000 --> 00:02:35,000 So, it looks like our server is up and running. 35 00:02:35,000 --> 00:02:40,000 Let's go ahead and generate our first scaffold. 36 00:02:40,000 --> 00:02:45,000 So, let's go ahead and stop the server, and we will be generating a new scaffold. 37 00:02:45,000 --> 00:02:49,000 If you want to learn more about scaffolds, go ahead and watch our videos on Ruby on Rails, 38 00:02:49,000 --> 00:02:51,000 so I'm just going to be going through this pretty quickly. 39 00:02:51,000 --> 00:02:56,000 We'll do "rails g" for Rails generate, and we're going to create a scaffold. 40 00:02:56,000 --> 00:03:01,000 And our model is going to be called a job. 41 00:03:01,000 --> 00:03:05,000 And if we look at our information, we need a title, description, 42 00:03:05,000 --> 00:03:10,000 company name and details link. 43 00:03:10,000 --> 00:03:18,000 Our title is going to be "string," our description is going to be "text," 44 00:03:18,000 --> 00:03:28,000 our company name will be "string," and the details link will be another string. 45 00:03:28,000 --> 00:03:30,000 A pretty simple model. 46 00:03:30,000 --> 00:03:35,000 So, let's see what happens when we install ithis. 47 00:03:35,000 --> 00:03:37,000 All right, that looks pretty good. 48 00:03:37,000 --> 00:03:39,000 However, I did notice something. 49 00:03:39,000 --> 00:03:42,000 We did generate html.erb files. 50 00:03:42,000 --> 00:03:45,000 Now, Nick and I decided we wanted to work on HAML and SASS, 51 00:03:45,000 --> 00:03:49,000 so let's go ahead and destroy all this, install HAML and SASS, 52 00:03:49,000 --> 00:03:55,000 and see if we can get the correct generators to work. 53 00:03:55,000 --> 00:04:05,000 So, we'll type in "rails destroy scaffold job." 54 00:04:05,000 --> 00:04:08,000 And that's gone and undone everything that the generator did. 55 00:04:08,000 --> 00:04:12,000 So, let's go ahead and install HAML. 56 00:04:12,000 --> 00:04:18,000 So, let's open up our gem file. 57 00:04:18,000 --> 00:04:24,000 And we're going to go ahead and add the gem HAML as a dependency. 58 00:04:24,000 --> 00:04:29,000 So, we'll add "gem haml" and we'll save that out. 59 00:04:29,000 --> 00:04:32,000 So, let's go back to our terminal and type in "bundle install" 60 00:04:32,000 --> 00:04:39,000 so we can install HAML. 61 00:04:39,000 --> 00:04:46,000 So now, we've installed so our Rails application will now be able to handle .haml files. 62 00:04:46,000 --> 00:04:52,000 Let's go ahead and run our generator again and see what happens. 63 00:04:52,000 --> 00:04:56,000 Now, we're still getting our index.html.erb, and that's because installing HAML 64 00:04:56,000 --> 00:05:03,000 only allows us to read HAML files, it doesn't install any generators 65 00:05:03,000 --> 00:05:07,000 for our scaffold to generate in HAML. 66 00:05:07,000 --> 00:05:11,000 Now, we could go in and rename the ERB file to HAML and recreate them all ourselves, 67 00:05:11,000 --> 00:05:16,000 but it'd be nice if our scaffold did come with HAML by default. 68 00:05:16,000 --> 00:05:21,000 Now, one tool we can do to have Rails generate HAML is use the gem called "HAML Rails." 69 00:05:21,000 --> 00:05:25,000 And this will add the generators that will create our different scaffold views 70 00:05:25,000 --> 00:05:29,000 in HAML instead of .erb files. 71 00:05:29,000 --> 00:05:37,000 So, we'll go back, add HAML Rails to our gem file, 72 00:05:37,000 --> 00:05:46,000 save it out, and run bundle install again. 73 00:05:46,000 --> 00:05:51,000 So now, we have HAML Rails installed. 74 00:05:51,000 --> 00:05:58,000 Let's go ahead and destroy our original scaffold again, 75 00:05:58,000 --> 00:06:05,000 and then let's go ahead and rerun our scaffold generator and see what we get. 76 00:06:05,000 --> 00:06:09,000 It looks like it generated the HAML views, which looks pretty good. 77 00:06:09,000 --> 00:06:17,000 So, if we go into our text editor, let's take a look. 78 00:06:17,000 --> 00:06:21,000 So, we have our jobs, looks like our index.html.haml. 79 00:06:21,000 --> 00:06:27,000 Looks like HAML to me and that'll be a good starting point for Nick to work off of. 80 00:06:27,000 --> 00:06:32,000 And so, I think we're good to go ahead and stick with this generator. 81 00:06:32,000 --> 00:06:34,000 So, let's go ahead and set up our database. 82 00:06:34,000 --> 00:06:37,000 Now, by default, we're using SQLite3, so we'll run the task 83 00:06:37,000 --> 00:06:43,000 "rake db: create" to go ahead and create our database. 84 00:06:43,000 --> 00:06:47,000 Done, and our generator set up a migration for us for our jobs, 85 00:06:47,000 --> 00:06:54,000 so we'll run "rake db: migrate." 86 00:06:54,000 --> 00:06:57,000 And it's gone ahead and created the table "jobs." 87 00:06:57,000 --> 00:07:06,000 So, if we start up our server, we can see where we're at. 88 00:07:06,000 --> 00:07:12,000 So, going back here to local host 3000, the root page is still going to be the welcoming page. 89 00:07:12,000 --> 00:07:16,000 And let's go to /jobs. 90 00:07:16,000 --> 00:07:18,000 All right, we got our normal listing here. 91 00:07:18,000 --> 00:07:25,000 We can create a new job, say "Ice Cream Taster." 92 00:07:25,000 --> 00:07:34,000 Add some text and we'll give it a company name, and we'll give it a details link. 93 00:07:34,000 --> 00:07:36,000 Save it out. 94 00:07:36,000 --> 00:07:41,000 We have our show page for jobs, and we have our listing here. 95 00:07:41,000 --> 00:07:45,000 And this is enough to send over to Nick where he'll begin working on the layout, 96 00:07:45,000 --> 00:07:48,000 the user interface, the user experience and all of that 97 00:07:48,000 --> 00:07:50,000 to actually make the app run properly. 98 00:07:50,000 --> 00:07:56,000 So, I think this is a good point for a commit, so let's go ahead and do just that. 99 00:07:56,000 --> 00:07:58,000 We'll stop the server. 100 00:07:58,000 --> 00:08:01,000 We'll do "git add ." 101 00:08:01,000 --> 00:08:15,000 We'll do "git commit," and we'll say we "Generated the jobs model." 102 00:08:15,000 --> 00:08:26,000 And I'm going to go ahead and "push origin master." 103 00:08:26,000 --> 00:08:29,000 And now it is up on GitHub. 104 00:08:29,000 --> 00:08:31,000 So now, I'm going to go ahead and send a message to Nick telling him about this, 105 00:08:31,000 --> 00:08:35,000 and letting him know he can start working on the views. 106 00:08:35,000 --> 00:08:39,000 "Hey Nick, I went ahead and ran the generator for our jobs, so if you pull now 107 00:08:39,000 --> 00:08:43,000 you'll have the jobs scaffold at /jobs." 108 00:08:43,000 --> 00:08:50,000 "I named the fields: title, description, company name and details_link, 109 00:08:50,000 --> 00:08:57,000 and of course you have the created_at and updated_at fields for the dates."