I'm new to both Scala and Play, so figured I'd start simple with a basic form (following the Play tutorials). I've been trying to solve the following error for 2 days now:
could not find implicit value for parameter messages: play.api.i18n.Messages
formWithErrors => BadRequest(views.html.contact.index(formWithErrors))
This is the code I have so far:
Controller:
package controllers.contact
import play.api._
import play.api.mvc._
import models.contact.UserData
class ContactController extends Controller {
def index = Action {
Ok(views.html.contact.index(UserData.form))
}
def create = Action { implicit request =>
UserData.form.bindFromRequest().fold(
formWithErrors => BadRequest(views.html.contact.index(formWithErrors)),
customer => Ok(s"Customer ${customer.name} created")
)
}
}
View:
@import play.api.data.Form
@import helper._
@import models.contact.UserData
@(form: Form[UserData])(implicit messages: Messages)
@main("") {
@helper.form(action = controllers.contact.routes.ContactController.create()) {
@helper.inputText(form("name"))
@helper.inputText(form("age"))
<input type="submit" value="Submit">
}
}
Model:
package models.contact
import play.api.data._
import play.api.data.Forms._
case class UserData(val name: String, val age: Int)
object UserData {
val form = Form(
mapping (
"name" -> text,
"age" -> number
)(UserData.apply)(UserData.unapply)
)
}
Am I missing something painfully obvious? A shove in the right direction would be really appreciate