Scala - 无法使用将play.api.mvc.Result作为请求处理程序返回的方法

Luc*_*cas 7 scala playframework playframework-2.0

我在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)
}
Run Code Online (Sandbox Code Playgroud)

}

但是,这导致错误:"无法使用返回play.api.mvc.Result作为请求处理程序的方法".

如果我应用动作生成器,它可以工作,但这不是我想要的方式.

有什么想法解决这个问题?

谢谢.

Pau*_*per 13

你需要做一个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)
  }
}
Run Code Online (Sandbox Code Playgroud)