Skip to content

Instantly share code, notes, and snippets.

@aaronlifton3
Created December 17, 2012 05:06
Show Gist options
  • Save aaronlifton3/4315872 to your computer and use it in GitHub Desktop.
Save aaronlifton3/4315872 to your computer and use it in GitHub Desktop.
play salat mongodb form example
val postForm: Form[Post] = Form (
mapping(
"name" -> nonEmptyText,
"description" -> nonEmptyText,
"group" -> ignored(Group.findOneByName("Test group").get.id),
"updated" -> optional(date)
)((name, description, group, updated) => Post(new ObjectId, name, description, Option(group), new java.util.Date, updated))
((post: Post) => Some((post.name, post.description, post.group.get, post.updated)))
)
def create = Action { implicit request =>
postForm.bindFromRequest.fold(
errors => BadRequest(views.html.posts.list(Post.findAll().toList, errors)),
value => {
Post.save(value)
Redirect(routes.Posts.list)
}
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment