Cover by Edd Dumbill, Simon St. Laurent, Eric J Gruber

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

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.

To get started, create a new application named guestbook:

$ rails new guestbook

Then change to that directory:

$ cd guestbook

And 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/guestbook03.)

$ rails generate scaffold Person name:string invoke active_record create db/migrate/20120220162923_create_people.rb create app/models/person.rb invoke test_unit create test/unit/person_test.rb create test/fixtures/people.yml route resources :people invoke scaffold_controller create app/controllers/people_controller.rb ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required