1 00:00:00,540 --> 00:00:04,800 Every time we load a page to create or edit the pet, we see what looks like 2 00:00:04,800 --> 00:00:08,790 a ruby debug string representing a pet near the top of the page. 3 00:00:08,790 --> 00:00:11,680 We don't want users to see that, so we need to remove it. 4 00:00:11,680 --> 00:00:14,055 But where is that page element coming from? 5 00:00:14,055 --> 00:00:17,425 Elements of a rails view can come from any of several places. 6 00:00:17,425 --> 00:00:20,704 Most HTML views are rendered using multiple files. 7 00:00:20,704 --> 00:00:24,651 First there's a layout that includes elements that are shared among all your 8 00:00:24,651 --> 00:00:25,508 site's pages. 9 00:00:25,508 --> 00:00:29,154 Nested within the layout there's usually a template with the HTML for 10 00:00:29,154 --> 00:00:33,440 an individual page like the owner index page or the pet edit page. 11 00:00:33,440 --> 00:00:37,530 Finally, there are often one or more partials nested within the template. 12 00:00:37,530 --> 00:00:41,130 These are used to share html code that would otherwise be repeated in more than 13 00:00:41,130 --> 00:00:42,690 one template. 14 00:00:42,690 --> 00:00:44,630 So how do we know which layout, template, and 15 00:00:44,630 --> 00:00:47,070 partials were used to render the current page? 16 00:00:47,070 --> 00:00:48,660 The rails log will tell us. 17 00:00:48,660 --> 00:00:52,600 If we load the pet's new page, for example, and 18 00:00:52,600 --> 00:00:57,030 then go to the terminal, we will see something like this in the rails log. 19 00:00:58,500 --> 00:01:02,760 It says that it rendered the pet/new.html.erb 20 00:01:02,760 --> 00:01:06,370 template within the application layout. 21 00:01:06,370 --> 00:01:12,968 So let's start looking for the source of our debug string in the app views, 22 00:01:12,968 --> 00:01:16,854 layouts, application.html.erb file. 23 00:01:16,854 --> 00:01:22,043 We see at the top, this is an HTML document, here's the heading, 24 00:01:22,043 --> 00:01:25,659 here's the body, the yield statement here, 25 00:01:25,659 --> 00:01:31,331 just yields to a particular template to render the actual page content. 26 00:01:31,331 --> 00:01:35,390 I don't really see anything that could render that pet debug string. 27 00:01:35,390 --> 00:01:40,470 Next let's check the views pets edit dot HTML dot your BE file. 28 00:01:40,470 --> 00:01:44,980 We see heading up here at the top, we see a request to render a form. 29 00:01:44,980 --> 00:01:50,140 We see links to show a particular pet and go back to the list of all pets. 30 00:01:50,140 --> 00:01:54,350 Again, I really don't see anything that would render a debug string here. 31 00:01:54,350 --> 00:01:56,430 Let's check our terminal one more time. 32 00:01:56,430 --> 00:02:02,620 The log also says that it rendered the pets/_form.html.erb file. 33 00:02:02,620 --> 00:02:05,510 Remember this underscore at the start of the filename indicates that it's 34 00:02:05,510 --> 00:02:06,440 a partial layout. 35 00:02:07,820 --> 00:02:09,070 Let's take a look in that file. 36 00:02:10,220 --> 00:02:12,810 Now what's this at the very top of the file. 37 00:02:12,810 --> 00:02:16,858 We've got ERBM bed tag with the current pet object we're working on. 38 00:02:16,858 --> 00:02:19,652 That's not supposed to be here, let's try removing it. 39 00:02:19,652 --> 00:02:23,110 Save our work and refresh your page. 40 00:02:24,460 --> 00:02:25,250 That took care of it. 41 00:02:26,630 --> 00:02:30,470 The debug string is gone from both the new pet and edit pet forms. 42 00:02:31,500 --> 00:02:33,570 This is supposed to be the vet app, yet for 43 00:02:33,570 --> 00:02:38,240 every page we load we see sample app in the browser title bar. 44 00:02:38,240 --> 00:02:43,910 The page title gets set by the title HTML element, but where's that coming from? 45 00:02:43,910 --> 00:02:47,328 Well if we reload the current page, we'll see this in the log. 46 00:02:47,328 --> 00:02:52,458 Let's load pets/edit.html.erb in our browser and 47 00:02:52,458 --> 00:02:55,473 see if we can find the title tag. 48 00:03:02,684 --> 00:03:05,060 There doesn't seem to be one there. 49 00:03:05,060 --> 00:03:08,018 So let's go back to the terminal and see what else is in the log. 50 00:03:08,018 --> 00:03:11,920 What's that layouts/application mentioned here? 51 00:03:11,920 --> 00:03:17,580 If we go look at app views layouts application.html.arb, 52 00:03:17,580 --> 00:03:20,500 we'll find the HTML template that all other templates for 53 00:03:20,500 --> 00:03:24,940 our app get rendered within, and it contains the title tag. 54 00:03:24,940 --> 00:03:32,490 If we update it to say Vet App, save our work and reload our page, 55 00:03:34,000 --> 00:03:37,980 we'll see that the title gets updated to Vet App in every page on our site. 56 00:03:40,250 --> 00:03:43,300 There's a copyright notice down here at the bottom of the page that seems 57 00:03:43,300 --> 00:03:44,090 a little outdated. 58 00:03:44,090 --> 00:03:48,030 Let me show you a trick that can save you a little time as long as you use 59 00:03:48,030 --> 00:03:48,640 it carefully. 60 00:03:49,700 --> 00:03:53,700 Most editors have a feature called find in files, find in project, or 61 00:03:53,700 --> 00:03:54,780 something similar. 62 00:03:54,780 --> 00:03:56,760 It will bring up a dialog that will let you search for 63 00:03:56,760 --> 00:04:01,050 a string not just in the current file, but in every file on the project. 64 00:04:01,050 --> 00:04:06,470 So we can copy the string shown in our browser, either the whole string or 65 00:04:06,470 --> 00:04:07,210 just part of it. 66 00:04:08,430 --> 00:04:11,940 And then choose Find, Find in Files from the menu. 67 00:04:11,940 --> 00:04:13,950 The menu names will depend on your editor, but 68 00:04:13,950 --> 00:04:16,310 that's where it is here in sublime text. 69 00:04:16,310 --> 00:04:20,020 Now we just paste that string here in the find box and hit enter to search. 70 00:04:21,100 --> 00:04:24,230 Your editor will scan for that string in every file of the project and 71 00:04:24,230 --> 00:04:26,280 show you a list of all the matches. 72 00:04:26,280 --> 00:04:30,322 In this case there's only one, and it's in the app, views, layouts, 73 00:04:30,322 --> 00:04:32,192 application layout file again. 74 00:04:32,192 --> 00:04:38,042 So we click on the match, which opens the file for editing and 75 00:04:38,042 --> 00:04:45,858 change the text to something more suitable like copyright 2016 Treehouse. 76 00:04:45,858 --> 00:04:51,390 If we save and reload our browser, we'll see the messages updated. 77 00:04:51,390 --> 00:04:54,570 So if there's some static text on your page that you need to update, 78 00:04:54,570 --> 00:04:58,370 you can often use your editor's find in files feature to locate it and 79 00:04:58,370 --> 00:04:59,680 save yourself a few steps.