Datasheet
Chapter 1: Building Resources
16
Route Display
If you find yourself becoming confused by all the RESTful routing magic, as of Version 2.0, Rails
provides a rake command,
routes , that gives you a complete list of the routes that have been defined in
your application (output has been truncated). For example:
$ rake routes
recipes GET /recipes
{:controller= > ”recipes”, :action= > ”index”}
formatted_recipes GET /recipes.:format
{:controller= > ”recipes”, :action= > ”index”}
POST /recipes
{:controller= > ”recipes”, :action= > ”create”}
POST /recipes.:format
{:controller= > ”recipes”, :action= > ”create”}
new_recipe GET /recipes/new
{:controller= > ”recipes”, :action= > ”new”}
formatted_new_recipe GET /recipes/new.:format
{:controller= > ”recipes”, :action= > ”new”}
edit_recipe GET /recipes/:id/edit
{:controller= > ”recipes”, :action= > ”edit”}
formatted_edit_recipe GET /recipes/:id/edit.:format
{:controller= > ”recipes”, :action= > ”edit”}
It ’ s a little tricky to see — you need some pretty long lines to lay this out, but the output is in four
columns: the named method stem that is used to access the route (for example,
edit_recipe , which can
be the stem to
edit_recipe_path or edit_recipe_url ), the HTTP verb that triggers this call, the
actual URL with symbols inserted, and then the controller and action called by the route.
Building Ingredients
Having now gotten a thorough tour of the new mechanisms that RESTful Rails provides by default, it ’ s
time for you to start writing some code and making this site come to life. The first task is to enable
simple entry of a recipe, and allow the most recently entered recipes to be displayed on the user - centered
front page, blog - style.
The following problems stand between you and that goal:
The database schema and sample code as generated do not associate recipes and ingredients, so
the forms that were created by the scaffold do not have a place to enter ingredient information.
❑
c01.indd 16c01.indd 16 1/30/08 4:02:25 PM1/30/08 4:02:25 PM