Permalink
Browse files

update_attribute performs rails callbacks which can create an endless…

… loop when saving if you have callbacks defined in your model.
  • Loading branch information...
1 parent d758720 commit 03ff0178d67eff4bf1805741d9664fc09d1aecbf @mphalliday committed Oct 13, 2011
Showing with 9 additions and 1 deletion.
  1. +9 −1 lib/delayed_paperclip.rb
View
10 lib/delayed_paperclip.rb
@@ -157,7 +157,15 @@ def process_delayed!
def post_process_styles_with_processing(*args)
post_process_styles_without_processing(*args)
- instance.update_attribute("#{name}_processing", false) if instance.respond_to?(:"#{name}_processing?")
+
+ # update_column is available in rails 3.1 instead we can do this to update the attribute without callbacks
+
+ #instance.update_column("#{name}_processing", false) if instance.respond_to?(:"#{name}_processing?")
+ if instance.respond_to?(:"#{name}_processing?")
+ instance.send("#{name}_processing=", false)
+ instance.class.update_all({ "#{name}_processing" => false }, instance.class.primary_key => instance.id)
+ end
+
end
alias_method_chain :post_process_styles, :processing

2 comments on commit 03ff017

@Bertg

Hi,

Could you provide a pull request for this one?

@mphalliday
Owner

For sure ... I'll do that now!

Please sign in to comment.