I’m writing a grails application, where I have region, district and streams. region contains district, so region_id is a foreign key for the district table. In other to query only rows associated with that region, I need to be able to pass the id to the URL.
Here is my UrlMappings.groovy:
static mappings = {
"/$controller/$action?/$id?"{
constraints {
// apply constraints here
}
}
"/"(controller:"/user")
"500"(view:'/error')
}
However, then I go to the link I created to forward to the district controller (default is list I see:
localhost:8080/project/district/list, but it does not have the region_id, so I was expecting localhost:8080/project/district/list/region_id='1'? or localhost:8080/project/district/list/id='1'?
Could someone please help me pointing out where is my mistake?
Thanks
/$controller/$action?/$id?means thatparamsmaps will have propertyidwith value from url. For url like/project/district/list/5this map returns 5 (assert params.id == 5).Also you can call your action by using following url:
/project/district/list?region_id=5and get 5 forparams.region_id.If you want to have different name,
region_idinstead of `id, and don’t want to pass it as a query parameter, you can make your own mapping:At this case this url is mapped strictly to controller
districtand actionlistandparams.region_idwill return 5 for/project/district/list/5