Anthony
Anthony

Reputation: 35928

creating a link from the controller

I want to create a link for an action from within the controller.

Link I want is: http://localhost:8080/myappname/color/show/1

So I've done this in my controller

new ApplicationTagLib().createLink(controller: "color", action: "show", 
 id: 1, absolute: true)

This however creates this link: http://localhost:8080/color/show/1

Notice that myappname is missing. How can I make a complete url?

Upvotes: 0

Views: 272

Answers (1)

Ian Roberts
Ian Roberts

Reputation: 122364

First, you don't need the new ApplicationTagLib() in a controller, you should just be able to use createLink or g.createLink. And secondly, check your grails.serverURL setting in Config.groovy, as it's this that is used when generating absolute links. With recent grails versions you should be able to remove the grails.serverURL setting entirely and it'll do the right thing.

Upvotes: 2

Related Questions