Datasheet

Chapter 1: Building Resources
17
You changed the default routing after the scaffolds were generated, and therefore the ingredient
forms, as generated, use invalid methods to create URLs.
The basic index listing of recipes is useful from an administrative point of view, but it is not
what you want to present to a user. In addition to the functional changes, you ll need it to be
much nicer looking.
That list will take you through the end of this chapter. Time to build a webapp!
Setting Up Your Database
Most of the work of setting up the initial database was already done when you created the resources and
generated migrations, but you still need to actually create the database instances. You ll need to go to the
database.yml file first and adjust the database information for all three database environments
development, test, and production. If you are using MySQL (version 5.x, please) and the database is on
your local development box, then you probably only need to put your root password into the file. (More
complicated database setups are discussed in Chapter 6 , The Care and Feeding of Databases. ” )
A late change in Rails 2.0.2 has made SQLite3 the default database for new Rails projects. The examples
in this book use MySQL for the database connections.
Once that is done, you can use Rake to do all the database creation work, without touching your MySQL
administration application. The first
rake command (new in Rails 2.0) is this:
rake db:create:all
This command goes through your database.yml file and creates a database schema for each database
listed for your local host.
Similarly, the
rake db:create command creates only the development environment. The command
creates empty database schemas. To populate the development environment with the tables and columns
defined in the migration, enter the following command:
rake db:migrate
And to take that development environment and copy it to the test database, enter the following
command:
rake db:test:prepare
This gives you all the database setup you need to get started.
Aligning Your Tests to the Nested Resource
I m a firm believer in automated testing unit, functional, and integration so I love the fact that Rails
includes such a complete test suite. It s very important to keep that suite current and running clean. I
know that some of the tests will fail based on the routing changes that were made, but the first thing to
c01.indd 17c01.indd 17 1/30/08 4:02:25 PM1/30/08 4:02:25 PM