diff options
Diffstat (limited to 'app/models/concerns')
-rw-r--r-- | app/models/concerns/attachmentable.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/app/models/concerns/attachmentable.rb b/app/models/concerns/attachmentable.rb new file mode 100644 index 000000000..995643ada --- /dev/null +++ b/app/models/concerns/attachmentable.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module Attachmentable + extend ActiveSupport::Concern + + included do + before_post_process :set_file_extensions + end + + private + + def set_file_extensions + self.class.attachment_definitions.each_key do |attachment_name| + attachment = send(attachment_name) + next if attachment.blank? + extension = Paperclip::Interpolations.content_type_extension(attachment, :original) + basename = Paperclip::Interpolations.basename(attachment, :original) + attachment.instance_write :file_name, [basename, extension].delete_if(&:empty?).join('.') + end + end +end |