paperclip_database_storage 3.0.2 → 3.0.3
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.
@@ -1,12 +1,11 @@
|
|
1
1
|
class PaperclipDatabaseStorage::AttachmentsController < ApplicationController
|
2
2
|
def get_attachment
|
3
3
|
conditions = {}
|
4
|
-
conditions[:attached_type] = params[:class].singularize.camelize if params[:class]
|
4
|
+
conditions[:attached_type] = params[:class].singularize.camelize(:upper) if params[:class]
|
5
5
|
conditions[:attached_id] = params[:id] if params[:id]
|
6
6
|
conditions[:attached_id] ||= params[:id_partition].gsub(/\//, '').to_i if params[:id_partition]
|
7
7
|
conditions[:attachment_name] = params[:attachment].singularize if params[:attachment]
|
8
8
|
conditions[:style] = params[:style] if params[:style]
|
9
|
-
|
10
9
|
|
11
10
|
attachments = PaperclipDatabaseStorage::Attachment.where(conditions)
|
12
11
|
|
@@ -14,6 +13,9 @@ class PaperclipDatabaseStorage::AttachmentsController < ApplicationController
|
|
14
13
|
raise ActionController::RoutingError.new('Too many images found. Check your route definition') if attachments.length > 1
|
15
14
|
|
16
15
|
attachment = attachments.first
|
17
|
-
send_data attachment.file_data,
|
16
|
+
send_data attachment.file_data,
|
17
|
+
:type => attachment.content_type,
|
18
|
+
:disposition => (attachment.content_type.strip =~ /^image/ ? 'inline' : 'attachment'),
|
19
|
+
:filename => (params[:filename] || attachment.attached.send(attachment.attached.attachment_definitions.select { |k, v| v[:storage] == :database }.keys.first).original_filename)
|
18
20
|
end
|
19
21
|
end
|
data/config/routes.rb
CHANGED
@@ -21,6 +21,6 @@ Rails.application.routes.prepend do
|
|
21
21
|
|
22
22
|
# Generate the default route, if necessary
|
23
23
|
if must_create_default_route
|
24
|
-
get Paperclip::Attachment.default_options[:url].gsub(/:id_partition/, '*id_partition') => 'paperclip_database_storage/attachments#get_attachment', :as => :default_pds
|
24
|
+
get Paperclip::Attachment.default_options[:url].gsub(/:id_partition/, '*id_partition').gsub(/:filename/, '*filename') => 'paperclip_database_storage/attachments#get_attachment', :as => :default_pds
|
25
25
|
end
|
26
|
-
end
|
26
|
+
end
|
@@ -23,8 +23,8 @@ module Paperclip
|
|
23
23
|
|
24
24
|
def get_attachment(style)
|
25
25
|
return PaperclipDatabaseStorage::Attachment.find(:first, :conditions => {
|
26
|
-
:style => style,
|
27
|
-
:attached_type => self.instance.class.name,
|
26
|
+
:style => style,
|
27
|
+
:attached_type => self.instance.class.name,
|
28
28
|
:attached_id => self.instance.id,
|
29
29
|
:attachment_name => self.get_attachment_definitions.keys.first
|
30
30
|
})
|
@@ -32,9 +32,9 @@ module Paperclip
|
|
32
32
|
|
33
33
|
def get_attachment_definitions
|
34
34
|
attachment_definitions = self.instance.class.attachment_definitions
|
35
|
-
|
35
|
+
|
36
36
|
if attachment_definitions.select { |k,v| v[:storage] == :database }.count > 1
|
37
|
-
raise Exception.new('paperclip-database does not support more than one attachment per model')
|
37
|
+
raise Exception.new('paperclip-database-storage does not support more than one attachment per model')
|
38
38
|
end
|
39
39
|
|
40
40
|
return attachment_definitions
|