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 2. Scaffolding, REST, and Routes

For centuries, scaffolding has helped builders provide access and support to buildings through the early stages of the construction process. Programmers, too, use temporary scaffolding code to lend structure and support until more permanent code is available. Rails automates scaffolding to make early coding more productive than ever before.

In Chapter 1, you saw how Rails took the most basic Rails request to call an action on a controller with a hash map of parameters. You also built some primitive views. In this chapter, we’ll start building a more powerful application called Photo Share, one that you can use to manage your personal photographs. We’ll use scaffolding to build the basic template, which includes a database-backed model, a controller, and a view. Along the way, you’ll learn the basics of a few critical Rails features, including:

  • Migrations. This database feature helps database developers create a database schema in steps, managing differences in the schema across all of your environments. Migrations will use Ruby code instead of database-specific SQL code.

  • REST and resources. Rails leans heavily on a style of Internet communication called REST, or Representational State Transfer. This HTTP-based communication strategy defines Internet resources where each URL or HTTP command of any kind will do a CRUD operation (Create, Read, Update, or Delete) on that resource. In Rails 2, each controller is a REST resource.

  • Named routes.

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