Friday, March 09, 2007

Specifying a default top-level-page with a route

We need to define a route: a translation rule, which is applied to the URL of the incoming request to a Rails application. Routes are defined in the file config/routes.rb.

In this case, we want to translate an empty URL into a call to the welcome action of the main controller. Add the following line, which must be the first map.connect line in the file:
map.connect '', :controller => "main", :action => "welcome"
This line establishes the rule that will perform the appropriate translation of anempty URL.

注意:To get this default page working correctly, you also have to remove the default default page public/index.html. A best practice is rename it to index.html.hidden, so that it won’t compete for top-level-page status with the main/welcome action.

No comments: