Alex
Alex

Reputation: 646

How to get absolute path to Grails application

In my application, a login controller should return redirect URL if client is authorized:

<path to grails app> + <another controller, method, params>

How can I get application URL?

Upvotes: 0

Views: 860

Answers (2)

Constantine
Constantine

Reputation: 141

For generic approach you can inject LinkGenerator and then call

linkGenerator.link(controller: "foo", action: "bar", absolute: true)

For some reason, tag use completely different logic.

Upvotes: 0

Brian Henry
Brian Henry

Reputation: 3171

You should be able to build a URL using the grails tags as method calls. createLink is likely what you want. This has action, controller, params and absolute as options to get a full URL to a controller action (you may need to configure the base url as noted in the docs). In an example in the first link, something like this would get the absolute URL to that resource:

g.createLink(action:"myact", controller:"somecontroller", params:[foo:'bar', boo:'far'], absolute:true)

Upvotes: 3

Related Questions