What it is the correct way to hide the /index action using route in a Grails app?
I want to be able redirect to a controller: "profile", action: "index" but have the url look like
http://foobar.com/profile
not
http://foobar.com/profile/index
UrlMappings.groovy
static mappings = {
"/profile"(controller:"profile", action: "index")
}
Or you could set your default action in the Controller
class BookController {
static defaultAction = "index"
}
If you are wanting to redirect to that URL then from within an action in a controller..
redirect uri: '/profile' // This one for the UrlMappings solution
or
redirect controller: 'profile' // This one for the defaultAction solution.
"/foo/" (controller:"foo", action:"index")
This goes in UrlMapping.groovy. UrlMapping.groovy works both ways, meaning that a g:link to controller foo and action index will also generate that shortened url.
You would need to do this for every controllers index though.
I tried setting:
"/$controller" {}
But no cigar, maybe someone else knows how this works.
Edit: Hah, I started writing this answer before you Nick, then spent 10 mins testing out various combinations of just the $controller thingie :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With