has_image 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +5 -0
- data/README +19 -1
- data/lib/has_image.rb +11 -4
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
2008-08-1 Norman Clarke <norman@randomba.org>
|
2
|
+
|
3
|
+
* Fixed a bug where overwriting a previous image triggered callbacks more
|
4
|
+
than once, causing errors.
|
5
|
+
|
1
6
|
2008-07-29 Norman Clarke <norman@randomba.org>
|
2
7
|
|
3
8
|
* Downcased generated file names to avoid potential issues on
|
data/README
CHANGED
@@ -65,7 +65,25 @@ Image with some thumbnails:
|
|
65
65
|
|
66
66
|
It also provides a view helper to make displaying the images extremely simple:
|
67
67
|
|
68
|
-
<%= image_tag_for(@photo
|
68
|
+
<%= image_tag_for(@photo) # show the full-sized image %>
|
69
|
+
<%= image_tag_for(@photo, :thumb => :square) # show the square thumbnail %>
|
70
|
+
|
71
|
+
The image_tag_for helper calls Rails' image_tag, so you can pass in all the
|
72
|
+
regular options to set the alt property, CSS class, etc:
|
73
|
+
|
74
|
+
<%= image_tag_for(@photo, :alt => "my cool picture", :class => "photo") %>
|
75
|
+
|
76
|
+
Setting up forms for has_image is simple, too:
|
77
|
+
|
78
|
+
<% form_for(@photo, :html => {:multipart => true}) do |f| %>
|
79
|
+
<p>
|
80
|
+
<%= f.label :image_data %>
|
81
|
+
<%= f.file_field :image_data %>
|
82
|
+
</p>
|
83
|
+
<p>
|
84
|
+
<%= f.submit %>
|
85
|
+
</p>
|
86
|
+
<% end %>
|
69
87
|
|
70
88
|
== Getting it
|
71
89
|
|
data/lib/has_image.rb
CHANGED
@@ -210,10 +210,17 @@ module HasImage
|
|
210
210
|
# Deletes the image from the storage.
|
211
211
|
def remove_images
|
212
212
|
return if has_image_file.blank?
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
213
|
+
self.class.transaction do
|
214
|
+
begin
|
215
|
+
# Resorting to SQL here to avoid triggering callbacks. There must be
|
216
|
+
# a better way to do this.
|
217
|
+
self.connection.execute("UPDATE #{self.class.table_name} SET has_image_file = NULL WHERE id = #{id}")
|
218
|
+
self.has_image_file = nil
|
219
|
+
storage.remove_images(self.id)
|
220
|
+
rescue Errno::ENOENT
|
221
|
+
logger.warn("Could not delete files for #{self.class.to_s} #{to_param}")
|
222
|
+
end
|
223
|
+
end
|
217
224
|
end
|
218
225
|
|
219
226
|
# Creates new images and removes the old ones when image_data has been
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_image
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Norman Clarke
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-08-01 00:00:00 -03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|