Search code examples
grailsurl-mapping

Grails, createLink generates wrong link


I am experiencing a weird issue with createlink. I have this in my gsp

<g:createLink controller="uni" action="show" id="1" />

I expect it to generate something like

"/uni/show/1"

However, it actually gives me

"/uni/create?id=1"

I also tried inline version as well,

${createLink(controller:'uni', action:'show', id:1) }

this also gives

"/uni/create?id=1"

Any help is greatly appreciated! Thanks!

UPDATE

I managed to fix it by adding a url mapping for "show" action

The problem may come from url mapping bug. I have this defined in my urlmappings.groovy

    "/uni/create"(controller:"uni"){
        action = [GET:"create", POST:"createDetail"]
    }

This somehow cause it to generate wrong link. I have no idea why, it will be nice if someone can explain it

After I add this line before "create", the problem is gone.

    "/uni/show/$id"(controller:"uni",action:"show")

Solution

  • You might have a problem in UrlMappings.groovy .

    There are some open bugs in reverse url mappings. What Grails version are you using?

    The best way to get around some of the bugs is to use named url mappings. In your case that shouldn't be necessary.