传递隐式参数

时间:2014-06-01 21:56:33

标签: scala playframework

下面的代码提供了错误在此处找不到任何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)
  }
}

如何使此参数可用?

1 个答案:

答案 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)
  }
}