Scala - Cannot use method returning play.api.mvc.Result as request handler

I have this controller in Scala:

def commonRedirect(anId: Long) = { implicit val aRule = CommonClient.getTheRule(anId) aRule match { case false โ‡’ Redirect("/general-rule/" + anId) case true โ‡’ Redirect("/custom-rule/" + anId) } 

}

but this leads to the error: "It is not possible to use a method that returns play.api.mvc.Result as a handler for requests."

If I applied Action Builder, it works, but this is not the way I want.

Any ideas to solve this problem?

Thanks.

+6
source share
1 answer

You need to do an Action .

 def commonRedirect(anId: Long) = Action { implicit val aRule = CommonClient.getTheRule(anId) aRule match { case false โ‡’ Redirect("/general-rule/" + anId) case true โ‡’ Redirect("/custom-rule/" + anId) } } 
+11
source

All Articles