Scala Can';不要在视图中使用Flash
我有一个主布局页面:Scala Can';不要在视图中使用Flash,scala,playframework,playframework-2.2,Scala,Playframework,Playframework 2.2,我有一个主布局页面: //layouts/main.scala.html @(title: String)(content: => Html)(implicit flash: Flash) <!DOCTYPE html> <html> <!-- .... --> <body> <h2>Here is the flash:</h2> @views.html.layouts.
//layouts/main.scala.html
@(title: String)(content: => Html)(implicit flash: Flash)
<!DOCTYPE html>
<html>
<!-- .... -->
<body>
<h2>Here is the flash:</h2>
@views.html.layouts._flash(flash)
<section class="content">My super content: @content</section>
</body>
</html>
//layouts/_flash.scala.html
@(flash: Flash)
@flash.data.foreach { case (k, v) =>
key, value: (@k, @v)
}
以及它的一个视图:
//application/index.scala.html
@layouts.main("Index") {
<h1>Index page</h1>
}
我试过这个:
//application/index.scala.html
@(implicit flash: Flash)
@layouts.main("Index") {
<h1>Index page</h1>
}
尝试将您的视图更改为:
@()(implicit flash: Flash)
@layouts.main("Index") {
<h1>Index page</h1>
}
您需要在某处提供Flash
对象的隐式定义-您已经在模板中指出需要一个对象,现在您需要在范围(例如在控制器中)中编写一个方法,返回Flash
//application/index.scala.html
@(implicit flash: Flash)
@layouts.main("Index") {
<h1>Index page</h1>
}
not enough arguments for method apply: (implicit flash: play.api.mvc.Flash)play.api.templates.HtmlFormat.Appendable in object index. Unspecified value parameter flash.
@()(implicit flash: Flash)
@layouts.main("Index") {
<h1>Index page</h1>
}
def index = Action { implicit request =>
Ok(views.html.application.index(request.flash))
}