Posted by & filed under Uncategorized.

Let’s take a look at the following Play! Scala artifacts…

Routes (note the option ‘?’ in the regex)

GET  /contacts/$filter<[a..z]?>  controllers.Contacts.list(filter: Option[String])

Contacts controller

def list(filter: Option[String]) = Action {
  // ...

View template

<a href="@routes.Contacts.list(None)">All</a>
<a href="@routes.Contacts.list(Some("a"))">A</a>


…the reverse routes of the view template are expanded to /contacts/ and /contacts/a.

To get rid…

…of the trailing slash ‘/’ in /contacts/ I chose the following config:

Routes (note the missing option ‘?’ in the regex)

GET  /contacts                  controllers.Contacts.list
GET  /contacts/$filter<[a..z]>  controllers.Contacts.listBy(filter: Option[String])

Contacts controller

def list = listBy(None)

def listBy(filter: Option[String]) = Action {
  // ...

View template

<a href="@routes.Contacts.list">All</a>
<a href="@routes.Contacts.listBy(Some("a"))">A</a>


… results in /contacts and /contacts/a as desired.

Are there better / simpler ways to achieve the same result?

Leave a Reply

  • (will not be published)