3

ok, so i asked, and got an answer on how to make a single controller instance case-insensitive vis-a-vis urls. I can do

"/mycontroller/$action?/$id?"(controller: "myController")

so when an app outside tries to reference link in our app, their lowercase urls ( :( sigh ) will work.

I need to extend this to include actions as well. So the question is, following the above approach, do i need put a url mapping in for each action?

/mycontroller/methodone/(controller: "myController", action: methodOne)
/mycontroller/methodtwo/(controller: "myController", action: methodTwo)

Something like the above?

hvgotcodes
  • 118,147
  • 33
  • 203
  • 236

2 Answers2

1

This is similar to the question below which I have answered and included source code

How to make my URL mapping case insensitive?

Community
  • 1
  • 1
Aaron Saunders
  • 33,180
  • 5
  • 60
  • 80
0

You can use a closure to calculate the action (or other parameters) programmatically:

"/mycontroller/$a?/$id?" {
    controller = 'myController'
    action = { params.a?.toLowerCase() }
}
Justin Ludwig
  • 3,311
  • 2
  • 24
  • 17
  • wouldnt this convert the action being called to lowercase? On the controller, the action is camel cased. So a /mycontroller/myaction needs to be converted to /myController/myAction to work – hvgotcodes Jul 14 '10 at 01:45
  • You're right, I read your question wrong -- I thought you wanted to go from camel- to lower-case. To go the other way, you'd need to get the list of actions for the controller (see http://stackoverflow.com/questions/2956294/reading-out-all-actions-in-a-grails-controller), and then build out a map of lower-case to camel-case names. Rather than putting all that code in your url-mappings config, though, you'd probably want to map "/mycontroller/$a?/$id?" to a new action in MyController, and have that action run the lower-to-camel code and forward the request on to the camel-cased action. – Justin Ludwig Jul 19 '10 at 17:35