tags:

views:

80

answers:

1

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.

+2  A: 

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)
  }
}
Jean Barmash
I am fairly new to Groovy and Grails. Could you tell me where I would declare this function named "transformUrl"? Thank you.
Amir Khawaja
Make the transformUrl function static and put it into the UrlMappings class.
Blacktiger