1 00:00:00,390 --> 00:00:04,344 Our site is working pretty well, but if we load our browser's 2 00:00:04,344 --> 00:00:08,840 developer tools, here in the console, we'll see several errors. 3 00:00:10,340 --> 00:00:14,315 It's trying to load CSS and JavaScript files, but it isn't finding them. 4 00:00:15,655 --> 00:00:18,195 When you're working in development mode, CSS and 5 00:00:18,195 --> 00:00:20,805 JavaScript are loaded through the asset pipeline. 6 00:00:20,805 --> 00:00:22,325 But because this is production and 7 00:00:22,325 --> 00:00:25,885 we need speed, Rails isn't configured to use the asset pipeline here. 8 00:00:27,005 --> 00:00:30,605 Instead, we're going to need to precompile all those assets. 9 00:00:30,605 --> 00:00:35,670 So let's go back to our terminal, hold the server. 10 00:00:35,670 --> 00:00:40,158 And we're going to need to run this command in the production 11 00:00:40,158 --> 00:00:44,734 environment again, so we'll do RAILS_ENV=production. 12 00:00:49,354 --> 00:00:51,800 We'll run the bin/rails executable again. 13 00:00:52,840 --> 00:00:56,825 And this time, we're going to run the task, assets:precompile. 14 00:00:59,670 --> 00:01:04,245 This will look through all your CSS, SAS, JavaScript, coffee script, etc, 15 00:01:04,245 --> 00:01:07,750 and compile those files out to the public assets directory. 16 00:01:09,110 --> 00:01:10,660 So, hit Enter to run the command. 17 00:01:12,870 --> 00:01:14,960 And it'll show you a log with all the files it wrote. 18 00:01:16,120 --> 00:01:20,340 Now normally in production, static assets like this would be served by a dedicated 19 00:01:20,340 --> 00:01:24,820 web server, such as Apache or Engine X, but we don't have those configured yet, so 20 00:01:24,820 --> 00:01:28,120 for this test app, we're gonna need to configure Rails itself to serve them. 21 00:01:29,630 --> 00:01:34,050 In a later workshop, we'll show you how to serve those files via your web server. 22 00:01:34,050 --> 00:01:35,500 To have Rails serve those files, 23 00:01:35,500 --> 00:01:37,890 we're going to need to set an environment variable. 24 00:01:37,890 --> 00:01:41,530 So let's edit our rbenv.vars file again. 25 00:01:41,530 --> 00:01:48,490 I'm gonna use the nano editor and edit the .rbenv-vars file. 26 00:01:48,490 --> 00:01:53,548 Move down to a new line, and we're going to set 27 00:01:53,548 --> 00:02:00,192 the RAILS_SERVE_STATIC_FILES environment variable. 28 00:02:00,192 --> 00:02:03,860 All caps, use underscores to separate the words. 29 00:02:03,860 --> 00:02:06,690 Then type an equal sign, and we're gonna set the value to true. 30 00:02:08,640 --> 00:02:11,290 Again, make sure there are no spaces surrounding the equal sign. 31 00:02:12,560 --> 00:02:15,897 Control load to write the file out, and Ctrl+X to exit, and 32 00:02:15,897 --> 00:02:17,920 that should be all there is to it. 33 00:02:17,920 --> 00:02:19,270 Let's try running our server again. 34 00:02:23,300 --> 00:02:25,740 Now let's go back to our browser and reload the page. 35 00:02:26,985 --> 00:02:29,177 And the warnings for CSS and JS files are gone. 36 00:02:34,256 --> 00:02:35,335 There you have it. 37 00:02:35,335 --> 00:02:39,410 We've installed Ruby on a production server, then deployed the Rails app to it. 38 00:02:39,410 --> 00:02:42,310 If you run into any trouble following any of these steps or 39 00:02:42,310 --> 00:02:45,160 have a slightly different environment than what's shown in the videos, 40 00:02:45,160 --> 00:02:48,110 be sure to check the teacher's notes for some tips. 41 00:02:48,110 --> 00:02:51,050 Most of the configuration you've set up can just live on the server 42 00:02:51,050 --> 00:02:53,770 from now on without any changes. 43 00:02:53,770 --> 00:02:56,670 But there are a few of these steps that you're going to need to repeat every time 44 00:02:56,670 --> 00:03:00,160 you release a new version of your app, such as pulling the changes from Git and 45 00:03:00,160 --> 00:03:01,330 restarting your web server. 46 00:03:02,500 --> 00:03:05,940 Doing it manually won't seem too bad at first, but over time, the potential for 47 00:03:05,940 --> 00:03:07,350 mistakes adds up. 48 00:03:07,350 --> 00:03:08,560 So, in an upcoming course, 49 00:03:08,560 --> 00:03:11,760 we're going to show you how to automate deploys to make them fast, easy, and safe.