开发者

How to temporarily disable acts_as_audited and actionmailer, run a script then reenable

This might be quite simple, but I am tearing my hair out. I have a script that I want to run on a daily basis, the script updates a ton of records( across 20 different models) and I dont really ca开发者_如何学运维re about maintaining an audit trail of these mass changes( or want to trigger 1000's of notifications). I really need a way of disabling acts_as_audited and action mailer temporarily, running the script and then re enabling them both.

Is there a simple way of doing this?

I am using ree/rails 2.3


Figured it out finally, this blog post: http://blog.viarails.net/2009/1/29/disabling-callbacks-in-an-activerecord-data-migration and this stackoverflow question helped How can I avoid running ActiveRecord callbacks?.

TO take it a step further you can also disable specific methods(lets say a notification that is done before_save) that are being called in the callback chain by doing this YourModel.before_save_callback_chain.select {|m| m.method == :your_notification_method_symbol}.clear

Just posting this so others may find it...enjoy!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜