I need to create a filter that is triggered on any save/update action in order to record the history of whats being done. I am having a problem getting id of the object that is being manipulated.
My controllers simplified:
class FooController {
static allowedMethods = [save: "POST", update: "POST", delete: "POST"]
def save = {
def fooInstance = new Foo(params)
if (fooInstance.save()) {
// params.id = fooInstance.id
return redirect(action: "show", id: fooInstance.id)
} else {
return render(view: "create", model: [fooInstance: fooInstance])
}
}
}
My filter needs to get the id of the object that I put in return redirect but unless I uncomment params.id = fooInstance.id above my filter gets null for params.id, I must be missing something dealing with scopes of the variable:
def filters = {
history(controller: '*', action: 'save|update|delete|restore') {
after = {
println params.id
}
}
}
I also tried passing model to after = expecting to get my fooInstance but I get null as well. Any ideas on whats wrong? Thanks.