1 00:00:00,790 --> 00:00:03,990 We're displaying some raw text for individual page records, but 2 00:00:03,990 --> 00:00:06,920 we'd like to display a full HTML page. 3 00:00:06,920 --> 00:00:09,100 For that we're going to need in ERB template. 4 00:00:10,120 --> 00:00:13,880 First, we need to get rid of the rendered text line from our controller. 5 00:00:13,880 --> 00:00:17,410 Rails only renders one thing per controller action, so if we left 6 00:00:17,410 --> 00:00:21,330 the render text call in it would prevent our template from being rendered. 7 00:00:21,330 --> 00:00:22,985 Now let's create a template file. 8 00:00:22,985 --> 00:00:27,650 Our request is being processed by the pages controllers show method. 9 00:00:27,650 --> 00:00:32,447 So by default rails will look for a template in the app, 10 00:00:32,447 --> 00:00:37,679 views, pages directory in a file named show.html.erb. 11 00:00:40,944 --> 00:00:43,220 Again watch out for typos in the filename. 12 00:00:44,260 --> 00:00:47,300 We don't have to loop over a collection of pages this time. 13 00:00:47,300 --> 00:00:51,080 We have only a single page stored in the page instance variable. 14 00:00:51,080 --> 00:00:54,490 So putting together an ERB template should be easy. 15 00:00:54,490 --> 00:00:57,050 First let's create a level one heading for the movie title so 16 00:00:57,050 --> 00:00:58,735 that it's displayed in large text. 17 00:00:58,735 --> 00:01:02,790 We'll set up a static h1 element in the middle of that we use an output 18 00:01:02,790 --> 00:01:03,590 embedding tag. 19 00:01:05,460 --> 00:01:09,778 And we'll display the title attribute of the object in the page instance variable. 20 00:01:13,139 --> 00:01:15,497 We'll use similar code to show the page body, but 21 00:01:15,497 --> 00:01:17,810 we use a paragraph element instead of a heading. 22 00:01:18,850 --> 00:01:21,640 Within that we'll embed the body attribute. 23 00:01:21,640 --> 00:01:27,590 So when at embedding tag page.body, and close the embedding tag. 24 00:01:27,590 --> 00:01:32,500 Save that, and go back to our list of all pages. 25 00:01:32,500 --> 00:01:36,570 Now if we click the link for an individual page the HTML view will be rendered. 26 00:01:37,760 --> 00:01:41,070 We'll see a heading with the page title and a paragraph with the page body. 27 00:01:42,690 --> 00:01:45,110 That's another tricky operation complete. 28 00:01:45,110 --> 00:01:47,310 You've learned how to create links that send a request for 29 00:01:47,310 --> 00:01:48,950 a particular model object. 30 00:01:48,950 --> 00:01:51,650 More importantly, you've learned how to take those requests, 31 00:01:51,650 --> 00:01:54,010 find the requested object, and display it in a view. 32 00:01:54,010 --> 00:01:55,790 You're doing great. 33 00:01:55,790 --> 00:01:58,430 Don't stop now though, because next we're going to learn how to 34 00:01:58,430 --> 00:02:00,950 handle requests to create new model objects.