我有一个简单的模型对象:
case class Region(id: String, revision: Option[String], name: String)
object Region {
// Returns Some(region) if successful, None if revision doesn't match the latest
// in the data store
def insertOrUpdate(region: Region): Promise[Option[Region]]
}
在我的控制器中,我想做这样的事情,但我不知道如何在响应中指示锁定失败。我想添加一个全局表单错误,但无法从 API 中看到。
def update(id: String) = Action {
implicit request => regionForm.bindFromRequest.fold(
formWithErrors => BadRequest(views.html.regions.edit(formWithErrors)),
region => Async{
Region.insertOrUpdate(region).map{
_ match {
case None => {
// How do I add a global form error indicating there were server side changes detected
BadRequest(views.html.regions.edit(regionForm.fill(region))
}
case Some(r) => Redirect(views.html.regions.index).flashing(("success", "Update successful")
}
}
)
}