9

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.

Joan
  • 4,079
  • 2
  • 28
  • 37
Lucas
  • 347
  • 4
  • 11

1 Answers1

14

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)
  }
}
Paul Draper
  • 78,542
  • 46
  • 206
  • 285
  • Thanks @paul-draper. I found in http://stackoverflow.com/a/28247637/1665906 that the required type for that is not just `Result` but `⇒ Result`, and that is an Action. – Lucas Feb 19 '16 at 14:18