私はこのような1コントローラのアクションを実装している:Scala Play 2.5フォームbindFromRequest:ここでHTTPリクエストを見つけることができませんか?
def doChangePassword = deadbolt.Restrict(List(Array(Application.USER_ROLE_KEY)))()
{ request => // <<<<<<<<<<<< here is the request
Future {
val context = JavaHelpers.createJavaContext(request)
com.feth.play.module.pa.controllers.AuthenticateBase.noCache(context.response())
val filledForm = Account.PasswordChangeForm.bindFromRequest
// compilation error here, it can't see the request ^^^^^^^
if (filledForm.hasErrors) {
// User did not select whether to link or not link
BadRequest(views.html.account.password_change(userService, filledForm))
} else {
val Some(user: UserRow) = userService.getUser(context.session)
val newPassword = filledForm.get.password
userService.changePassword(user, new MyUsernamePasswordAuthUser(newPassword), true)
Redirect(routes.Application.profile).flashing(
Application.FLASH_MESSAGE_KEY -> messagesApi.preferred(request)("playauthenticate.change_password.success")
)
}
}
}
実装は上記のコンパイルエラーにつながる
:
{ request => // <<<<<<<<<<<< here is the request
:私はから2行目を変更した場合、
[error] /home/bravegag/code/play-authenticate-usage-scala/app/controllers/Account.scala:74: Cannot find any HTTP Request here
[error] val filledForm = Account.PasswordChangeForm.bindFromRequest
[error] ^
[error] one error found
しかし、 〜
{ implicit request => // <<<<<<<<<<<< here is the request
それはコンパイル...しかし、なぜですか?あなたはこのように、スコープのimplicit request
を必要とする
要求は、暗黙のスコープであることが必要です。なければ、それはコンパイルされません。 – cchantep