每天一剂Rails良药之Make your URLs Meaningful(and pretty)

这篇内容没什么价值,《Agile Rails》里的Routing Request一节讲述的比较详细了
ActionController::Routing::Routes.draw do |map|
  map.connect ':controller/service.wsdl', :action => 'wsd'
  map.connect ':controller/:action/:id'
  map.connect ':user', :controller=> 'recipes',
                      :action => 'list',
                      :filter => 'user'

其实上面的代码是调用map.connect()方法:
map.connect(String path, Hash options)

再就是Named Routes:
map.popular 'popular/:tag', :controller => 'recipes',
                            :action => 'list',
                            :tag => '',
                            :filter => 'popular'

这会生成popular_url()和popular_path()方法,前者是绝对路径的链接,后者是相对路径的链接

你可能感兴趣的:(Web,Rails)