Reputation: 310
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")
Upvotes: 2
Views: 3368
Reputation: 2349
if the action is not defined you will get default behavior
http://grails.org/doc/1.1/ref/Tags/createLink.html
action (optional) - The name of the action to use in the link, if not specified the default action will be linked
Upvotes: 0
Reputation: 5310
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.
Upvotes: 3