O'Reilly logo

Rails: Up and Running, 2nd Edition by Curt Hibbs, Lance Carlson, Bruce Tate

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 5. Working with Views

So far, you’ve taken a quick pass through Rails controllers and views in Chapter 1, where you learned how a basic Rails request works. Then, you took a deeper dive into controllers by using the scaffolding feature to build basic models, views, and controllers for your application in Chapter 2. In Chapters 3 and 4, you fleshed out the Active Record models, adding the relationships you need to make each one of them work for Photo Share.

It may not seem like it, but the lion’s share of this demo application is built. Most of the remaining work is related to views and testing. In this chapter, you will learn how to:

  • Take control of the views rendered through scaffolding

  • Handle relationships in our views through building in links

  • Render common pieces of a website (such as a navigation bar) through layouts

  • Work with Rails routes to build friendlier URLs

  • Reuse shared common pieces of a web page in fragments called partials

  • Manage CSS styles to keep your application more consistent

The Big Picture

Let’s step back for a moment to review the basic processing steps that happen from the time the server receives a URL request to when Rails finally returns the resulting HTML response (affectionately known as the big picture):

  1. The web server receives a request consisting mostly of a URL, some optional parameters, and a message body. The web server sends the request to the Rails application for handling.

  2. The web server will handle requests for static resources, such as images ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required