You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
610 B

  1. # frozen_string_literal: true
  2. module Attachmentable
  3. extend ActiveSupport::Concern
  4. included do
  5. before_post_process :set_file_extensions
  6. end
  7. private
  8. def set_file_extensions
  9. self.class.attachment_definitions.each_key do |attachment_name|
  10. attachment = send(attachment_name)
  11. next if attachment.blank?
  12. extension = Paperclip::Interpolations.content_type_extension(attachment, :original)
  13. basename = Paperclip::Interpolations.basename(attachment, :original)
  14. attachment.instance_write :file_name, [basename, extension].delete_if(&:blank?).join('.')
  15. end
  16. end
  17. end