I created the upadte method, but when I test it it shows the error NoSuchElementException: None.get
UserController
object UserController extends Controller {
def update(id:Long) = DBAction { implicit rs =>
var user = simpleUserForm.bindFromRequest.get
user.id = Users.toOption(id)
Users.update(user)
Redirect(routes.UserController.list)
}
val simpleUserForm :Form[User] = Form {
mapping(
"firstName" -> nonEmptyText,
"lastName" -> nonEmptyText,
"email" -> email,
"birthDate" -> nonEmptyText,
"phone" -> nonEmptyText,
"username" -> text,
"password" -> nonEmptyText
)(UserForm.fromSimpleForm)(UserForm.toSimpleForm)
}
}
edit.scala.html
@import models.auth.Users
@(title: String, user:models.auth.User)
@main(title){
<form method="post" action="@controllers.auth.routes.UserController.update(Users.toLong(user.id))">
<input type="text" placeholder="First Name" name="firstName" value="@user.firstName"/><br/>
<input type="text" placeholder="Last Name" name="lastName" value="@user.lastName"/><br/>
<input type="email" placeholder="Email" name="email" value="@user.email" /><br/>
<input type="text" placeholder="Phone" name="phone" value="@user.phone" /><br/>
<input type="text" placeholder="Birthdate(dd/MM/yyyy)" name="birthDate" value="@user.birthDate" /><br/>
<input type="text" placeholder="Username" name="username" value="@user.username" /><br/>
<input type="submit" value="Update User" />
}
routes
POST /user/:id/ controllers.auth.UserController.update(id:Long)
I've done create, read and delete, but by update I found the error in that line
var user = simpleUserForm.bindFromRequest.get
the error is NoSuchElementException: None.get