Grails UrlMapping - cannot set params.id for controller

I am trying to create an UrlMapping to map some static url to a controller action, but I cannot install params.id

. I'm working through Grails in action, so I'm not sure what is wrong here.

the code:

class UrlMappings
...
static mappings={
    "/timeline/chuck_norris"(controller:'post',action:'timeline',id:'chuck_norris')
...
}

      

In PostController

def timeline{
   def user = User.findByUserId(params.id)
   [user:user]
}

      

Error: No signature of method: ...findByUserId() is applicable for argument types: () values: []

What's wrong with the above code? I am using grails 1.2.2.

+2


a source to share


1 answer


You need to use closure:

"/timeline/chuck_norris"{
            controller = 'post'
            action = 'timeline'
           id = 'chuck_norris"
        }

      



or like this:

"/timeline/$id"{
               controller = 'post'
                action = 'timeline'
}

      

+3


a source







All Articles