How To Create Permalinks With Grails
2010-02-04 06:55:59 | 0 Comment
I am developing a stackoverflow.com clone with Grails in order to digest it. I wanted to create permalinks or slugs of the questions for the urls. Since I already had the regular expression for this -I'm using it on this blog- all I needed to know how to use it with Groovy.
The solution is simple as always. There is nothing hard in programming. Anyway, solution is here:
def title = "How To Create Permalinks With Grails"
slug = title.toLowerCase().replaceAll(" ", "-").replaceAll(/[^\sA-Za-z-0-9]/, "")
println slug
# result: how-to-create-permalinks-with-grails
Enjoy! :)

Comments
Leave a Response