user5167056
user5167056

Reputation:

Implicit messages Scala Play framework

I am trying to follow this:

ToDoList Tutorial

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.

Upvotes: 2

Views: 1316

Answers (3)

Anomaly
Anomaly

Reputation: 1061

I know this question is old, but I had the same problem trying to go through the tutorial with Play 2.6.x, and resolved it by following the instructions at https://stackoverflow.com/a/30800825/1033203, except that instead of using:

(implicit messages: Messages)

in my view signature, I needed:

(implicit messagesProvider: MessagesProvider)

Upvotes: 0

Teena Vashist
Teena Vashist

Reputation: 111

You can pass implicit request in the action and implicit play.api.i18n.Messages in the template.

@(tasks: List[Task], taskForm: Form[String])(implicit messages: play.api.i18n.Messages)

Upvotes: 0

Bilk
Bilk

Reputation: 438

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.

Upvotes: 2

Related Questions