我们希望按如下url来查看articles archive:
http://localhost/articles
http://localhost/articles/2007
http://localhost/articles/2007/9
http://localhost/articles/2007/9/28
我们可以这样定义routes:
[code]
# in routes.rb
map.connect 'articles/:year/:month/:day', :controller => 'articles',
:month => nil, :day => nil, :requirements => { :year => /\d{4}/ }
[/code]
http://localhost/articles
http://localhost/articles/2007
http://localhost/articles/2007/9
http://localhost/articles/2007/9/28
我们可以这样定义routes:
[code]
# in routes.rb
map.connect 'articles/:year/:month/:day', :controller => 'articles',
:month => nil, :day => nil, :requirements => { :year => /\d{4}/ }
[/code]
本文介绍了一种使用Ruby on Rails进行URL路由配置的方法,通过具体的代码示例展示了如何定义日期格式的文章归档路径。

被折叠的 条评论
为什么被折叠?



