Created
January 25, 2011 05:11
-
-
Save pmcneil/794542 to your computer and use it in GitHub Desktop.
This demonstrates a pattern suggested here http://bit.ly/h24hXy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.nerderg.test | |
class TestController { | |
def index = { | |
} | |
def changeColour = { | |
withPerson { | |
log.debug dump() | |
hairColour = 'blond' | |
render(view: "changeColour", model: [person: delegate]) | |
} | |
} | |
def withPerson(id='id', Closure c) { | |
def person = Person.get(params[id]) | |
if(person) { | |
c.delegate = person | |
c.resolveStrategy = Closure.DELEGATE_FIRST | |
c.call() | |
return person | |
} else { | |
flash.message = "The person was not found." | |
redirect action: "index" | |
} | |
} | |
} | |
class Person { | |
int height | |
int age | |
String sex | |
String hairColour | |
static constraints = { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment