How can I avoid running ActiveRecord callbacks?

Posted by Ethan on Stack Overflow See other posts from Stack Overflow or by Ethan
Published on 2009-03-10T23:52:22Z Indexed on 2010/04/13 5:32 UTC
Read the original article Hit count: 272

Filed under:
|
|

I have some models that have after_save callbacks. Usually that's fine, but in some situations, like when creating development data, I want to save the models without having the callbacks run. Is there a simple way to do that? Something akin to...

Person#save( :run_callbacks => false )

or

Person#save_without_callbacks

I looked in the Rails docs and didn't find anything. However in my experience the Rails docs don't always tell the whole story.

UPDATE

I found a blog post that explains how you can remove callbacks from a model like this:

Foo.after_save.clear

I couldn't find where that method is documented but it seems to work.

© Stack Overflow or respective owner

Related posts about activerecord

Related posts about ruby