【问题标题】:Custom path for resourceful route资源丰富的路径的自定义路径
【发布时间】:2012-02-21 23:38:51
【问题描述】:

我希望能够做到……

资源:帖子

... 并且能够将上下文 url 自定义为 ...

: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 助手获取路由所需的额外参数?

如果不是,这似乎值得提出功能请求。

【问题讨论】:

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


    【解决方案1】:

    听起来你需要类似的东西:

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

    【讨论】:

      猜你喜欢
      • 2011-07-10
      • 1970-01-01
      • 1970-01-01
      • 2019-07-02
      • 2015-09-26
      • 2020-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多