-1

I have the following named UrlMapping

name 'admin_user' :"/admin/user/$action?/$id?"(controller:'userAdmin')

On a different page site/edit.gsp (/admin/site/edit) I am calling:

<g:link  mapping="admin_user" action='create' class="create" >New User</g:link>

But its generating

/admin/site/create

basically ignoring my mapping parameter. Any help on what I a doing wrong?

doelleri
  • 19,232
  • 5
  • 61
  • 65
Nix
  • 57,072
  • 29
  • 149
  • 198

3 Answers3

0

This mapping seems to be OK. I got it right in my Grails v2.0.4 environment.

<g:link  mapping="admin_user" action='create' class="create" >New User</g:link>

produces a link to:

/admin/user/create

and

<g:link  mapping="admin_user" action='create' class="create" id="3">New User</g:link>

generates

/admin/user/create/3

You may check if the UrlMapping.groovy is in the right place, or the docs of the Grails version you adopt.

coderLMN
  • 3,076
  • 1
  • 21
  • 26
0

So I finally got down to the bottom of this it was an issue with two url mappings that conflicted.

name 'admin_user' :"/admin/user/$action?/$id?"(controller:'userAdmin')
"/$controller/$action?/$id?"()

It was ignoring the first and always using the second. I eventually had to just abandon using the admin prefix and actually go with /admin/userAdmin/ I defined

"/admin/$controller/$action?/$id?"()

And then used createLink with controller='userAdmin'.

Whenever I needed a link to /user/xxx I explicitly defined it.

Big pain in the arse....

Nix
  • 57,072
  • 29
  • 149
  • 198
-1

It looks like you aren't creating or using your named mapping correctly. You're trying to use both a named mapping and an action, but the action form is taking precedence, which is why you end up with a link to /controller/action. Based on the docs, you need to have a specific named mapping for your action, which looks more like this:

name createAdminUser: "/admin/user/create" {
    controller = 'userAdmin'
}

You can still pass named parameters like $id? (which doesn't seem to make sense for a create) via params="[name: value]". Use it in your view like:

<g:link mapping="createAdminUser" class="create">New User</g:link>
doelleri
  • 19,232
  • 5
  • 61
  • 65