I have read many SO answer about grails urlMapping but didn't find any answer that fit my needs.
Let say I have two Domain: Project
and Contributor
class Project{
String name;
String urlName; //is the name converted to url
static belongsTo = [contributor: Contributor]
}
//a contributor has many Projects, then in the `Project`
//table I have `contributor_id`
class Contributor{
String userName;
static hasMany = [projets: Project]
}
My urls looks like this:
www.mysite.com/frank/frank-s-nice-project/comments
www.mysite.com/bill/bill-s-great-project/comments
www.mysite.com/lucie/lucie-s-awesome-project/comments
Which is corresponding to : www.mysite.com/username/urlName/comments
username
comes from Contributor Domain.
urlName
comes from Project Domain
How can I set urlMappgings.groovy
to always redirect to the same controller/action
when url matches "/$username/$urlName/comments"
I have tried like this but with no success.
static mappings = {
"/$username/$urlName/comments"(controller: 'comment', action: 'index)
}
Thanks for your help.
I answer my question to make it as accepted answer,
This actually works
static mappings = {
"/$username/$urlName/comments"(controller: 'comment', action: 'index)
}