资源丰富的路线的自定义路径

时间:2012-01-30 04:43:48

标签: ruby-on-rails routing rack rails-routing

我希望能够......

资源:帖子

...并且能够自定义上下文网址...

:year/:month/:day/:id

... 仍然能够......

post_path post

这会生成/2012/1/1/something-something

然而,似乎我必须......

get ':year/:id' => 'posts#show', as: 'posts'

然后在视图中我必须......

post_path post.year, post.id代替post_path post

有没有让post_path帮助器获取路径所需的额外参数?

如果不是这似乎值得一个功能请求。

1 个答案:

答案 0 :(得分:2)

听起来像你需要的东西:

match "posts/:year/:month/:day/:id" => "posts#show", :constraints => { :year => /\d{4}/, :month => /\d{2}/, :day => /\d{2}/ }