Reputation: 46613
I'm creating a route that should have an optional/ignored last term.
Like so:
/product/12345/Dark-Knight-Rises # last term is just there for a nice URL
I was thinking, from reading the docs, that I'd just be able to wildcard the last term:
match 'product/:uid/*full_name' => 'product#view', :via => [:get]
That didn't work. I did get this to work:
match 'product/:uid/:full_name' => 'product#view', :via => [:get]
match 'product/:uid' => 'product#view', :via => [:get]
But, well, it seems like this should be doable in one line. Yes?
Upvotes: 0
Views: 45
Reputation: 6728
Below single line should work
match 'product/:uid/:full_name' => 'product#view', :via => [:get]
Upvotes: 0
Reputation: 19839
match 'product/:uid(/:full_name)' => 'product#view', :via => [:get]
is what you are looking for
The parenthesis make the full_name an optional parameter which you can just ignore since all you want is a pretty URL.
Upvotes: 2