Amir Khawaja
Amir Khawaja

Reputation: 469

URL with hyphens in Grails 1.1.1 or Grails 1.2 M4

Is there a way to configure Grails 1.1.1 or Grails 1.2 M4 to map a multi-word controller or action written in PascalCase or camelCase to automatically map to a URI with hyphens separating the words?

For example, if I have a controller named MoreInformation with a function named boardOfDirectors, I would like the URI to resemble:

http://domain.com/more-information/board-of-directors

Is this possible? Thank you.

Upvotes: 2

Views: 301

Answers (1)

Jean Barmash
Jean Barmash

Reputation: 4788

Assuming you have a method transformURL which converts hyphenated case to CamelCase, something like this should do it.

class UrlMappings {
static mappings = { 
  "/$initialController/$initialAction?/$id?"{
            controller = transformUrl(initialController)
            action = transformUrl(initialAction)
  }
}

Upvotes: 3

Related Questions