Showing posts with label Best Practice. Show all posts
Showing posts with label Best Practice. Show all posts

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.

Thoughts of Ruby on Rails Workshop

应该不仅仅教授Ruby和Rails的最常用知识和技巧,还应该教授一套自己的develop pickups——就是从针对每一类问题的众多解决方法中挑选出一种,作为自己的selected pattern,并一般不在使用其它解决方法。从而达到对一种方法越用越熟,熟而生巧的效果。