4

I have a URL mapping as below:

static mappings = {
        name register: "/register" {
            controller = "account"
            action = "createuser"
        }
}

and I want to redirect using this mapping from a controller with something like:

redirect mapping:'register'

Unfortunately, unlike createLink tag lib, it seems that redirect does not accept mapping as input parameter.

So my question is : How can I use my named URL mapping for redirection ?

fabien7474
  • 16,300
  • 22
  • 96
  • 124
  • Curious why you need to do it by the mapping vs redirect(controller:'account', action:'createUser') – Gregg Oct 06 '10 at 13:06
  • 1
    Because, if I change my register mapping, I will not have to change the code but only url mappings. Also, code is more readable – fabien7474 Oct 06 '10 at 13:36

1 Answers1

8

You can combine the two:

redirect url: createLink(mapping: 'register')
Burt Beckwith
  • 75,342
  • 5
  • 143
  • 156
  • If the application name (e.g. app.name set in application.properties) is part of the url, then you will need to add the parameter `absolute: true` to the createLink call, to avoid having the application show up twice in the resulting redirect (eg http://localhost:8080/myapp/myapp/register) – Ian Robertson Jul 20 '15 at 16:13