views:

1207

answers:

1

I have the following UrlMapping in my Grails UrlMappings class:

  "/$something/" {
      controller = "controllerName"
      action = "actionName"
      constraints {
      }
  }

Requests to both "/foobar/" and "/foobar" gets routed to the correct controller and action.

However, URL:s created using g:link does not end with slash ("/") as expected.

The GSP code ...

<g:link controller="controllerName" action="actionName" params="[something: 'foobar']">...</g:link>

... generates the HTML output ...

<a href="/foobar">...</a>

How do I make Grails generate the link as specified by the URL pattern? That is including the ending slash.

+1  A: 

Unfortunately this is not possible with Grails' default URL mapping. Slashes are handled in a special way. And this behaviour is hard-coded in the Grails core. It could be overridden using a plugin though.

As a workaround (probably not applicable) I can provide to use it that way:

<g:link uri="/foobar/">Foo Link</g:link>

This should produce a link with a trailing slash.

Siegfried Puchbauer