public
Rubygem
Description: A lightweight and opinionated but hackable library for attaching images to ActiveRecord models.
Homepage:
Clone URL: git://github.com/norman/has_image.git
Fixed a bug where overwriting a previous image triggered callbacks more than
once, causing errors.
norman (author)
Fri Aug 01 08:26:44 -0700 2008
commit  52bfffe2cc0947400efe31f342689835967a19f5
tree    d08dde25917161ee919d67341d1f721e7c2b2673
parent  703760e4bbf15ffad3a4ce0a6670355482f6693c
...
 
 
 
 
 
1
2
3
...
1
2
3
4
5
6
7
8
0
@@ -1,3 +1,8 @@
0
+2008-08-1 Norman Clarke <norman@randomba.org>
0
+  
0
+  * Fixed a bug where overwriting a previous image triggered callbacks more
0
+    than once, causing errors.
0
+
0
 2008-07-29 Norman Clarke <norman@randomba.org>
0
 
0
   * Downcased generated file names to avoid potential issues on
...
1
2
3
4
 
 
5
6
7
...
1
2
 
 
3
4
5
6
7
0
@@ -1,7 +1,7 @@
0
 Gem::Specification.new do |s|
0
   s.name = "has_image"
0
-  s.version = "0.1.5"
0
-  s.date = "2008-07-29"
0
+  s.version = "0.1.6"
0
+  s.date = "2008-08-01"
0
   s.add_dependency('mini_magick', '>= 1.2.3')
0
   s.rubyforge_project = 'has-image'  
0
   s.summary = "Lets you attach images with thumbnails to active record models."
...
210
211
212
213
214
215
216
 
 
 
 
 
 
 
 
 
 
 
217
218
219
...
210
211
212
 
 
 
 
213
214
215
216
217
218
219
220
221
222
223
224
225
226
0
@@ -210,10 +210,17 @@ module HasImage
0
     # Deletes the image from the storage.
0
     def remove_images
0
       return if has_image_file.blank?
0
-      storage.remove_images(self.id)
0
-      update_attribute(:has_image_file, nil)
0
-    rescue Errno::ENOENT
0
-      logger.warn("Could not delete files for #{self.class.to_s} #{to_param}") 
0
+      self.class.transaction do
0
+        begin
0
+          # Resorting to SQL here to avoid triggering callbacks. There must be
0
+          # a better way to do this.
0
+          self.connection.execute("UPDATE #{self.class.table_name} SET has_image_file = NULL WHERE id = #{id}")
0
+          self.has_image_file = nil
0
+          storage.remove_images(self.id)
0
+        rescue Errno::ENOENT
0
+          logger.warn("Could not delete files for #{self.class.to_s} #{to_param}")
0
+        end
0
+      end
0
     end
0
     
0
     # Creates new images and removes the old ones when image_data has been

Comments