Monday, 25 June 2012

get app context in grails view

I have a custom link that I need to render so the search engines can index the search terms more effectively. Specifically, I wanted to generate something like this:

http://mytestdomain.local:8080/tweetcommendation/review/business-name/1_Informotion%20Software_Vancouver,%20BC

However, I found that I couldn't do this using createLink, because it only had the concept of controller / action mapping, and my /review/business-name/${businessName} is not mapped to a controller (it's just defined in DataSource.groovy).

Originally, I had something like this:
${request.contextPath}/review/business-name/${it.id}_${it.name}_${it.location}

That way works. However, I actually found a cleaner solution that I thought I'd share:

${resource(file: "review/business-name/${it.id}_${it.name}_${it.location}")}

1 comment: