Skip to content

Instantly share code, notes, and snippets.

@reidiculous
Created August 23, 2012 19:12
Show Gist options
  • Save reidiculous/3440493 to your computer and use it in GitHub Desktop.
Save reidiculous/3440493 to your computer and use it in GitHub Desktop.
dynamic RESTful url mappings

this follows the pattern I see in the Grails docs but yields the following error:

MissingPropertyException: No such property: json for class: java.lang.String
class UrlMappings {
static mappings = {
// REST - why not working??
"/$controller/$id.json" {
action = [GET: 'show', PUT: 'update', DELETE: 'delete']
}
"/$controller.json" {
action = [GET: 'list', POST: 'create']
}
"/$controller/$action?/$id?"{
constraints {
// apply constraints here
}
}
"/"(view:"/index")
"500"(view:'/error')
}
}
@mrjones2014
Copy link

its because "/$controller.json" is trying to access a property json on controller, which is a string. In Groovy, you can go 1 property deep with string interpolation. Try "/${controller}.json".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment