module Spree class Attachment < Spree::Asset ATTACHMENT_ATTRIBUTES = %i[alt attachment_content_type attachment_file_name attachment_updated_at id position type].freeze PERMITTED_ATTACHMENT_ATTRIBUTES = %i[alt attachment position viewable_id viewable_type].freeze ALLOWED_CONTENT_TYPES = %w[application/pdf text/plain].freeze has_attached_file :attachment, url: '/spree/attachments/:id/:basename.:extension', path: 'spree/attachments/:id/:basename.:extension' validate :no_attachment_errors validates_attachment :attachment, content_type: { content_type: ALLOWED_CONTENT_TYPES } def no_attachment_errors errors.add :attachment, "Paperclip returned errors for file #{attachment_file_name}" if attachment.errors.any? end end end