[Play20] Cannot find any HTTP Request here

1,814 views
Skip to first unread message

damien Gouyette

unread,
May 2, 2012, 12:37:08 PM5/2/12
to play-fr...@googlegroups.com
Hello everybody,

I'm in trouble with action composition,

I had the following method in an administration controller 

def Authenticated(f: (User, Request[AnyContent]) => Result) = {
    Action {
      request =>
        request.session.get("email").flatMap(u => User.findByEmail(u)).map {
          user =>
            f(user, request)
        }.getOrElse(Unauthorized("401 - unautoriezd"))
    }
  }



when i use it in a method without form submission it's ok  : 

def create = Authenticated {
    (user, request) =>
      Ok(views.html.administration.create(postForm))
  }

But when i use it in a method with bindFromRequest  : 

def save = Authenticated {
    (user, request) =>
      postForm.bindFromRequest.fold(
        formWithErrors => BadRequest(views.html.administration.create(formWithErrors)),
        post => {
          Post.create(post)
          Redirect(routes.Administration.index())
        }
      )
  }

I have the following errors.

Cannot find any HTTP Request here

In /Users/damiengouyette/developpement/sources/play/plogengine-scala/app/controllers/Administration.scala at line 70.

66
67
68  def save = Authenticated {
69    (user, request) =>
70      postForm.bindFromRequest.fold( 
71        formWithErrors => BadRequest(views.html.administration.create(formWithErrors)),
72        post => {
73          Post.create(post)
74          Redirect(routes.Administration.index())


Any ideas ?

Guillaume Bort

unread,
May 2, 2012, 1:48:38 PM5/2/12
to play-fr...@googlegroups.com
bindFromRequest needs an implicit Request in the scope, or pass it explicitely:

postForm.bindFromRequest(request)
> --
> You received this message because you are subscribed to the Google Groups
> "play-framework" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/play-framework/-/4iiIwTdPD8oJ.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to
> play-framewor...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/play-framework?hl=en.



--
Guillaume Bort
Reply all
Reply to author
Forward
0 new messages