Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add default ID partitioning for attachments

git-svn-id: http://svn.techno-weenie.net/projects/plugins/attachment_fu@2833 567b1171-46fb-0310-a4c9-b4bef9110e78
  • Loading branch information...
commit 66548c06427c9e7d175b33cc80f634d3221a706b 1 parent dcd5c2a
technoweenie authored
View
1  CHANGELOG
@@ -1,5 +1,6 @@
* April 2, 2007 *
+* add default ID partitioning for attachments
* add #binmode call to Tempfile (note: ruby should be doing this!) [Eric Beland]
* Check for current type of :thumbnails option.
* allow customization of the S3 configuration file path with the :s3_config_path option.
View
10 lib/technoweenie/attachment_fu/backends/file_system_backend.rb
@@ -18,7 +18,7 @@ def self.included(base) #:nodoc:
# The optional thumbnail argument will output the thumbnail's filename.
def full_filename(thumbnail = nil)
file_system_path = (thumbnail ? thumbnail_class : self).attachment_options[:path_prefix].to_s
- File.join(RAILS_ROOT, file_system_path, attachment_path_id, thumbnail_name_for(thumbnail))
+ File.join(RAILS_ROOT, file_system_path, *partitioned_path(thumbnail_name_for(thumbnail)))
end
# Used as the base path that #public_filename strips off full_filename to create the public path
@@ -28,7 +28,13 @@ def base_path
# The attachment ID used in the full path of a file
def attachment_path_id
- ((respond_to?(:parent_id) && parent_id) || id).to_s
+ ((respond_to?(:parent_id) && parent_id) || id).to_i
+ end
+
+ # overrwrite this to do your own app-specific partitioning.
+ # you can thank Jamis Buck for this: http://www.37signals.com/svn/archives2/id_partitioning.php
+ def partitioned_path(*args)
+ ("%08d" % attachment_path_id).scan(/..../) + args
end
# Gets the public path to the file
Please sign in to comment.
Something went wrong with that request. Please try again.