Action create shows form:
def create = Action {
Ok(html.post.create(postForm))
}
How can i modify this action so that for GET request it would give out form and for the POST request it would process user input data, as if it were a separate action:
def newPost = Action { implicit request =>
postForm.bindFromRequest.fold(
errors => BadRequest(views.html.index(Posts.all(), errors)),
label => {
Posts.create(label)
Redirect(routes.Application.posts)
}
)
}
Wthat i mean is i want to combine this two actions.
UPDATE1: I want a single Action that serves GET and POST requests
I tried once to accomplish similar thing, but I realized that I wasn’t using framework like it was meant to be used. Use separate GET and POST methods like @paradigmatic showed and in cases like you specified
"If we take adding comments to another action, we wouldn't be able to get infomation on post and comments in case an error occured (avoding copy-paste code)."– just render the page at the end of controller method with the view you like? and for errors etc. you can always use flash scope too?http://www.playframework.org/documentation/2.0.2/ScalaSessionFlashyou could also render this form page with two or more beans and send them to controller side to catch related error messages and data.?