开发者

Optional string in Rails route

开发者 https://www.devze.com 2023-01-16 20:38 出处:网络
I want to add an optional string to an URL. I\'ve tried this: map \":category/p:id(/:title)\" => ...

I want to add an optional string to an URL. I've tried this:

map ":category/p:id(/:title)" => ...

The title parameter should be op开发者_运维知识库tional, so that the user can insert a optional title or leave it. Sadly this does not work. Any ideas?


If I remember correctly, it depends on what version of Ruby on Rails you are using.

Rails 3

  
    match ':category/p:id(/:title)', :to => 'category#edit'
  

Rails 2

  
    map.connect ':category/p:id/:title, :controller => 'category', :action => 'edit', :title => 'default title'
  
0

精彩评论

暂无评论...
验证码 换一张
取 消