When you add a custom route, make it a named route so you have url helper methods to easily link to that new route. See episode for details. 当你添加一条自定义路由,使之成为一条命名路由,这样就有了一个url的helper方法,用这个helper方法就能很轻松的链接到这个自定义路由。详情参见本节内容。 ActionController::Routing::Routes.draw do |map| map.connect ':controller/:action/:id.:format' map.connect ':controller/:action/:id' map.connect '', :controller=>'projects',:action=>'index' #normal route map.home '', :controller=>'projects',:action=>'index' #named route ,generate home_path & home_url map.task_archive 'tasks/:year/:month', :controller=>'tasks', :action=>'archive' #named route, we can use it like this : task_archive_path(2007,5) 本文转自 fsjoy1983 51CTO博客,原文链接:http://blog.51cto.com/fsjoy/132170,如需转载请自行联系原作者