tags:

views:

76

answers:

2

The

<g:link controller="foo" action="bar">foobar</g:link>

tag sometimes works, that is is renders as

<a href="grailsapp/foo/bar">foobar</a>

and sometimes it doesn't. In this case I'll get a

<a href="grailsapp/">foobar</a>

Does anyone know what conditions cause this tag to fail to expand? Also is there any way to debug the tag expansion logic?

+2  A: 

To debug - the file you need is at

$GRAILS_HOME\src\java\org\codehaus\groovy\grails\plugins\web\taglib\ApplicationTagLib.groovy

Jean Barmash
+1  A: 

This might not solve your problem or everyone else's, but I had this same problem occur for me. I had a /mywebapp/session/login URL that I wanted to link to, but <g:link controller="session" action="login"> just resolved to /mywebapp/.

But it turns out that I had mapped my context root "/" to show the login page. I had thought it would redirect, but really it exposed the Session.login page at "/". So, when grails was told to create a link to go to Session.login, the simplest link it could come up with that would take me there was "/". So "/" was correct after all.

If you still can't get it working, but you still need a way to generate links relative to your context root, you can use <a href="${createLink(uri: '/foo/bar')}">

Josh Justice