ADBlock is blocking some content on the site

ADBlock errore

Routes in play2: How to match a part of the url

StackOverflow https://stackoverflow.com/questions/9312148


There are some urls like:


They will be mapped to a method:

def showImage(id: String) = Action {
    val image = Image.findById(id).get
    Ok.sendFile(new File(image.path)

Note that the id is the only part of filename showed in url: 111111, 222222, 333333

So I write a mapping in routes:

GET  /images/$id<\w+>.*          controllers.Images.showImage(id)

In the part $id<\w+>.*, id is matching the id, and .* match the suffix which will be ignored.

But the syntax is incorrect, the error message is:

Identifier expected

How to fix it?


It’s not currently possible to do that with Play 2. As a workaround you can process your argument in the controller action:

GET    /images/:id       controllers.Images.showImage(id)
def showImage(idWithExt: String) = Action {
  val id = idWithExt.takeWhile(_ != '.')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow