开发者

Problem accessing params.id in the filter

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. A开发者_高级运维ny ideas on whats wrong? Thanks.


Look into this plugin http://grails.org/Hibernate+Events+Plugin or the grails audit log plugin. I think they will get you pretty far along.

It is a different approach then you mention in your question, but I think you might prefer it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜