我正在使用 PlayFramework 2.1.4 和 SecureSocial 2.1.1。
我定义routes
如下,将请求设置为POST
.
POST /postComment controllers.Application.postComment
一开始很顺利,但在 SecuredAction 之后,请求变为GET
. 日志:
[info] application - onRouteRequest() requestHander = POST /postComment
[debug] application - [securesocial] anonymous user trying to access : '/postComment'
[debug] application - [securesocial] assets controller = controllers.ReverseAssets
[info] application - onRouteRequest() requestHander = GET /login
[error] application - [securesocial] can't find provider for id userpass
[info] application - onRouteRequest() requestHander = GET /authenticate/facebook
[debug] application - [securesocial] user logged in : [SocialUser(IdentityId( ...)]
[info] application - onRouteRequest() requestHander = GET /postComment
[warn] application - onHandlerNotFound() requestHander = GET /postComment
我该怎么办?请给我你的建议。
表单是这样的(createComment.scala.html)。
@helper.form(action=routes.Application.postComment){
@helper.textarea(commentForm("body"))
<div class="actions">
<input type="submit" class="btn primary" value="submit">
</div>
}
这是 Application.scala
case class CommentData(body: String, vote: String)
object Application extends Controller with SecureSocial {
val commentForm = Form(mapping("body" -> nonEmptyText)(CommentData.apply)(CommentData.unapply))
def postComment = SecuredAction { implicit request =>
val id=session.get("targetCommentId");
commentForm.bindFromRequest.fold(
formWithErrors => {
BadRequest(views.html.createComment(commentForm)).withSession(session+"targetCommentId"->id.toString)
},
commentData => {
val id = request.user.identityId.userId
val body = commentData.body
application.Application.createComment(id, body)
Ok(views.html.topiclist())
})
}
}