I am trying to follow this:
Basic tutorial to learn about the Play framework. I receive an error message on this line:
@inputText(taskForm("label"))
Where the error message is this:
could not find implicit value for parameter messages: play.api.i18n.Messages
I render this view in my controller like this:
def tasks = Action {
Ok(views.html.index(Task.all(), taskForm))
}
I've Googled the error message and it seems the implicit message is for internationalizing strings, but I've yet to find a post on how to actually fix this error and I'm also confused because this is an official tutorial, and the code doesn't compile.
答案 0 :(得分:2)
Try using an implicit request
in the Action
, and put an implicit lang
at the top of the template.
def tasks = Action { implicit request =>
Ok(views.html.index(Task.all(), taskForm))
}
And at the top of the index template:
@(tasks: List[Task], taskForm: Form[String])(implicit lang: Lang)
The request
provides the Lang
for the template.
答案 1 :(得分:0)
我知道这个问题已经过时了,但我尝试使用Play 2.6.x完成教程时遇到了同样的问题,并按照https://stackoverflow.com/a/30800825/1033203上的说明解决了这个问题,但不是使用:
(implicit messages: Messages)
在我看来签名中,我需要:
(implicit messagesProvider: MessagesProvider)
答案 2 :(得分:0)
您可以在操作中传递隐式请求,并在模板中隐式播放play.api.i18n.Messages。
@(tasks: List[Task], taskForm: Form[String])(implicit messages: play.api.i18n.Messages)