]> cat aescling's git repositories - mastodon.git/commitdiff
Make the paperclip filename interpolator smarter about the :original style
authorEugen Rochko <eugen@zeonfederated.com>
Sun, 5 Mar 2017 22:03:49 +0000 (23:03 +0100)
committerEugen Rochko <eugen@zeonfederated.com>
Sun, 5 Mar 2017 22:03:49 +0000 (23:03 +0100)
If an :original gets converted into another format, it would get saved as
original_filename *anyway*, so generating the extension is pointless and
yields bad results for when you change the style definition later. This way,
old gifs will still have correct URLs

config/initializers/paperclip.rb

index 71a7b514ec9a27884685ec4c9f8cdb9349af5fd5..580a3196e6f5b3b4fc0b33d99ea400a9aa0e2085 100644 (file)
@@ -2,6 +2,11 @@
 
 Paperclip.options[:read_timeout] = 60
 
+Paperclip.interpolates :filename do |attachment, style|
+  return attachment.original_filename if style == :original
+  [basename(attachment, style), extension(attachment, style)].delete_if(&:empty?).join('.')
+end
+
 if ENV['S3_ENABLED'] == 'true'
   Aws.eager_autoload!(services: %w(S3))