Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Docs updated

  • Loading branch information...
commit a459c3b18587e4888963237ecb732d8e085f8249 1 parent 972362b
@alvarosanchez authored
Showing with 5 additions and 5 deletions.
  1. +5 −5 README.md
View
10 README.md
@@ -21,12 +21,12 @@ class Book {
String title
String sanitizedTitle
- def beforeInsert() {
- sanitizedTitle = title.asFriendlyUrl()
+ def beforeValidate() {
+ if (!sanitizedTitle) sanitizedTitle = title?.asFriendlyUrl()
}
static constraints = {
- sanitizedTitle unique:true //As an alternative, you may decide to make sanitizedTitle replace default id.
+ sanitizedTitle unique:true //As an alternative, you may decide to make sanitizedTitle replace the default id.
}
}
```
@@ -36,7 +36,7 @@ And given the following URL mapping:
class UrlMappings {
static mappings = {
- "/book/$title"(controller:'book', action:'show')
+ "/book/$sanitizedTitle"(controller:'book', action:'show')
"/$controller/$action?/$id?"{
constraints {
@@ -54,7 +54,7 @@ You can do the following in your controller:
class BookController {
def show() {
- [book: Book.findBySanitizedTitle(params.title)]
+ [book: Book.findBySanitizedTitle(params.sanitizedTitle)]
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.