lib/milton/attachment.rb in citrusbyte-milton-0.1.5 vs lib/milton/attachment.rb in citrusbyte-milton-0.1.7

- old
+ new

@@ -44,10 +44,23 @@ # not to orphan the file def filename=(name) write_attribute :filename, AttachableFile.sanitize_filename(name) end + # Simple helper, same as path except returns the directory from + # .../public/ on, i.e. for showing images in your views. + # + # @asset.path => /var/www/site/public/assets/000/000/001/313/milton.jpg + # @asset.public_path => /assets/000/000/001/313/milton.jpg + # + # Can send a different base path than public if you want to give the + # path from that base on, useful if you change your root path to + # somewhere else. + def public_path(options={}, base='public') + path(options).gsub(/.*?\/#{base}/, '') + end + # The path to the file, takes an optional hash of options which can be # used to determine a particular derivative of the file desired def path(options={}) attached_file.path(options) end @@ -124,10 +137,10 @@ # If no options are given then returns the path and filename to the # original file. def path(options={}) options.empty? ? File.join(dirname, filename) : Derivative.new(filename, options).path end - + # Returns the full directory path up to the file, w/o the filename. def dirname File.join(root_path, partitioned_path) end