views:

32

answers:

2

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?

A: 

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

"/mycontroller/$a?/$id?" {
    controller = 'myController'
    action = { params.a?.toLowerCase() }
}
Justin Ludwig
@Justin, wouldnt this convert the action being called to lowercase? On the controller, the action is camel cased. So a /mycontroller/myactionneeds to be converted to /myController/myAction to work
hvgotcodes
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
+1  A: 

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

http://stackoverflow.com/questions/2809588/how-to-make-my-url-mapping-case-insensitive/3295614#3295614

Aaron Saunders