Created
December 17, 2012 05:06
-
-
Save aaronlifton3/4315872 to your computer and use it in GitHub Desktop.
play salat mongodb form example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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