我在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)
}
}
但是,这会导致错误:"无法使用返回play.api.mvc.Result作为请求处理程序的方法"。
如果我应用动作生成器,它可以工作,但这不是我想要的方式。
有任何解决此问题的想法吗?
感谢。
答案 0 :(得分: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)
}
}