ОТКЛЮЧИТЬ АДБЛОК

ADBlock блокирует некоторый контент на сайте

ADBlock errore

вопрос

There are some urls like:

http://localhost:9000/images/111111.jpg
http://localhost:9000/images/222222.png
http://localhost:9000/images/333333.gif

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