f00860
f00860

Reputation: 3576

Optional string in Rails route

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

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

The title parameter should be optional, so that the user can insert a optional title or leave it. Sadly this does not work. Any ideas?

Upvotes: 1

Views: 304

Answers (1)

murphyslaw
murphyslaw

Reputation: 636

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'
  

Upvotes: 3

Related Questions