如何暂时禁用acts_as_audited和actionmailer,运行脚本然后重新启用
这可能很简单,但我却抓狂了。我有一个想要每天运行的脚本,该脚本更新了大量记录(跨越 20 个不同的模型),而且我并不真正关心维护这些大规模更改的审核跟踪(或者想要触发 1000 条通知) 。我确实需要一种暂时禁用acts_as_audited 和action mailer 的方法,运行脚本,然后重新启用它们。
有没有一种简单的方法可以做到这一点?
我正在使用 ree/rails 2.3
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 care 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
终于弄清楚了,这篇博客文章: http://blog.viarails.net/2009/1/29/disabling-callbacks-in-an-activerecord-data-migration 这个 stackoverflow 问题有帮助如何避免运行 ActiveRecord 回调?。
要更进一步,您还可以通过执行以下操作来禁用在回调链中调用的特定方法(假设在 before_save 完成的通知)
YourModel.before_save_callback_chain.select {|m| m.method == :your_notification_method_symbol}.clear
只是发布此内容,以便其他人可以找到它...享受!
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!