Stefan Kendall
Stefan Kendall

Reputation: 67802

Creating a Grails URLMapping for all methods in a controller?

How do I create a urlmapping that maps controller A essentially as controller B?

I thought something like this would work, but no dice.

  "/my/"(controller: 'other', action: '*')

Upvotes: 1

Views: 3280

Answers (1)

ataylor
ataylor

Reputation: 66059

When you specify a controller in UrlMappings, leave off the trailing "Controller" (e.g. "my", instead of "myController"). You also need some way of choosing which action.

You probably want something like "/my/$action?"(controller: 'my'), which maps urls like /my/foo to the foo action in MyController. The trailing question mark means the action part of the url is optional; /my will trigger MyController.index.

Note that the grails convention is already to map /my to MyController with the default mapping "/$controller/$action?/$id?"{}, so you don't need a special UrlMapping for your example. You might want to consider just using the defaults and follow the convention.

Upvotes: 5

Related Questions