1
votes

In Rails I can say:

get 'path1/:path2/(:path3)' => "controller#action"

where path3 is an optional named parameter and there is a slash before it. In Play Framework I only found the way to do something like this but only for parameters with ?.

How do I do that in Play Framework?

1

1 Answers

8
votes

Support for optional path parameters has been dropped with 2.1, see:

We removed Option[...] support in path bindables since it doesn't make sense to have a optional path parameter. You can implement your own path bindable that supports it if you please.

A possible solution (which is implementing a bindable yourself) is described here.

But the simplest solution might be to simply define two routes:

GET   /path/:a                   controllers.Application.show(a, b = "default")
GET   /path/:a/:b                controllers.Application.show(a, b)

By the way, the things you are referring to are path parameters and query parameters (the part after ? in an URL). Named parameters are a completely different (and unrelated) story.