user122299
user122299

Reputation:

grails <g:link tag sometimes works and sometimes doesn't>

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?

Upvotes: 1

Views: 827

Answers (3)

Flavio Valentim
Flavio Valentim

Reputation: 43

Only one remark which may be useful:

If you are in a file .gsp into the folder:

  • view
  • controller_name
  • your_view.gsp

This works fine: >> <a href="${createLink(uri: '/foo/bar')}">

If you are in a file .gsp into the src/template (for example to modify the list.gsp, create.gsp, etc.):

You have to add a backslash like this:<a href="\${createLink(uri: '/foo/bar')}">

Upvotes: 0

Josh Justice
Josh Justice

Reputation: 21374

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')}">

Upvotes: 0

Jean Barmash
Jean Barmash

Reputation: 4788

To debug - the file you need is at

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

Upvotes: 1

Related Questions