下面的代码提供了错误在此处找不到任何HTTP请求标头,因为 views.html.texts 期望隐式请求参数在范围内:
import play.api.mvc._
object MyController extends Controller {
private def renderAction(result: Seq[String] => SimpleResult) = Action {
implicit request =>
val strs = Seq("a", "b", "c")
result(strs)
}
def renderSomething = renderAction { strings =>
views.html.texts(strings)
}
}
如何使此参数可用?
答案 0 :(得分:1)
result
函数应将request
作为参数。
import play.api.mvc._
object MyController extends Controller {
private def renderAction(result: Seq[String] => Request[AnyContent] => SimpleResult) = Action {
implicit request =>
val strs = Seq("a", "b", "c")
result(strs)(request)
}
def renderSomething = renderAction { strings => implicit request =>
views.html.texts(strings)
}
}