Dims
Dims

Reputation: 51019

How to compute only URL in grails (without <a> tag)?

If I write

<g:link controller="book" action="list">Book List</g:link>

in GSP it will render to something like

<a href="/book/list">Book List</a>

in HTML.

But what if I wish to call this URL with AJAX? I don't need <a> tag anymore, I need only url /book/list.

How to compute it?

Note that it should depends on application context, trailing slash etc.

Upvotes: 0

Views: 44

Answers (1)

quindimildev
quindimildev

Reputation: 1280

Use createLink instead, here is the doc

Some examples:

 // generates "/shop/book/show/1"
<g:createLink action="show" id="1" />
// generates "/shop/book/show?foo=bar&boo=far"
<g:createLink action="show" params="[foo: 'bar', boo: 'far']"/>

// generates "/shop/book"
<g:createLink controller="book" />

// generates "/shop/book/list"
<g:createLink controller="book" action="list" />

// generates "/shop/book/list"
<g:createLink url="[action:'list',controller:'book']" />

Upvotes: 2

Related Questions