我正在尝试使用form
中的数据创建并保存新的 Supply 模型。
以下是 SuppliesController 的相关代码:
def submitSupplyOffer = SecuredAction.async { implicit request =>
SupplyForm.form.bindFromRequest.fold(
form => Future.successful(BadRequest(views.html.supplies.index(request.identity, form))),
data => {
val supply = Supply(
id = UUID.randomUUID(),
userID = request.identity.userID,
resource = data.resource,
amount = data.amount
)
for {
supply <- supplyService.save(supply.copy())
result <- Redirect(routes.Application.index())
} yield {
result
}
}
)
}
这是我得到的错误:
提前致谢!
答案 0 :(得分:1)
Redirect.apply
会返回Result
,而不是Future[Result]
,因此您需要将其从for-comprehension中删除:
def submitSupplyOffer = SecuredAction.async { implicit request =>
SupplyForm.form.bindFromRequest.fold(
form => Future.successful(BadRequest(views.html.supplies.index(request.identity, form))),
data => {
val supply = Supply(
id = UUID.randomUUID(),
userID = request.identity.userID,
resource = data.resource,
amount = data.amount
)
for {
supply <- supplyService.save(supply.copy())
} yield Redirect(routes.Application.index())
}
)
}