Chapter 5. Accelerating Development with Scaffolding and REST

The example in the previous chapter contained the key components you need to work with Rails and began to demonstrate how they work together. Rails is more than just a set of components, however—it’s a tightly knit package that includes tools to get you started more quickly. Rails can even teach you some best practices while making your work easier.

A First Look at Scaffolding

So, how do Rails developers build applications more quickly? One key piece of the puzzle is scaffolding. Instead of building a detailed controller and view, you can let Rails put up an interface to your data. In most cases, the scaffolding will be temporary, something you build on and replace, but in some cases the scaffolding may be enough to do what you need. The scaffolding also provides an excellent way to see what Rails’ creators think is a good way to accomplish common tasks.

Note

If you’re wondering what happened to the instant one-line dynamic scaffolding that used to be a constant part of the Rails sales pitch, it’s gone. It disappeared in Rails 2.0, replaced by generated scaffolding that provides a much more solid foundation.

To get started, create a new application named people:

$ rails people

Then create a model and supporting scaffolding with a single command from the command line. (You can also find all of these files in ch05/guestbook003.)

$ ruby script/generate scaffold Person name:string exists app/models/ exists app/controllers/ ...

Get Learning Rails: Live Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.