Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala - Cannot use a method returning play.api.mvc.Result as a Handler for requests

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 result in the error: "Cannot use a method returning play.api.mvc.Result as a Handler for requests".

If I apply an Action Builder, it works, but this is not the way that I want.

Any ideas to resolve this?

Thanks.

like image 654
Lucas Avatar asked Feb 18 '16 13:02

Lucas


1 Answers

You need to make 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)
  }
}
like image 53
Paul Draper Avatar answered Sep 20 '22 17:09

Paul Draper