In case you want to ensure files are written/deleted only if the commit succeeds, this plugin is for you.
The plugin simply adds the after_commit
method to your ActiveRecord models and ensures that the code in the block is only executed if and after the top-most transaction succeeds.
Once the plugin is in the vendor/plugins folder, you can write the following code in your save/destroy hooks (or anywhere else that is run inside a transaction):
def some_callback after_commit do # write file, clear cache, etc end end
Get the plugin here
The plugin is now part of the new versions gem which enables automatic versioning, multiversions and shared attachments.
Gaspard Bucher
comments