def attachment_field(object_name, method, object:, **options)
      options[:data] ||= {}

      definition = object.send(:"#{method}_attachment_definition")
      options[:accept] = definition.accept

      if options[:direct]
        url = Refile.attachment_upload_url(object, method, host: options[:host], prefix: options[:prefix])
        options[:data].merge!(direct: true, as: "file", url: url)
      end

      if options[:presigned] and definition.cache.respond_to?(:presign)
        url = Refile.attachment_presign_url(object, method, host: options[:host], prefix: options[:prefix])
        options[:data].merge!(direct: true, presigned: true, url: url)
      end

      options[:data][:reference] = SecureRandom.hex
      options[:include_hidden] = false

      attachment_cache_field(object_name, method, object: object, **options) + file_field(object_name, method, options)
    end
def attachment_field(object_name, method, object:, **options)
      options[:data] ||= {}

      definition = object.send(:"#{method}_attachment_definition")
      options[:accept] = definition.accept

      if options[:direct]
        url = Refile.attachment_upload_url(object, method, host: options[:host], prefix: options[:prefix])
        options[:data].merge!(direct: true, as: "file", url: url)
      end

      if options[:presigned] and definition.cache.respond_to?(:presign)
        url = Refile.attachment_presign_url(object, method, host: options[:host], prefix: options[:prefix])
        options[:data].merge!(direct: true, presigned: true, url: url)
      end

      options[:data][:reference] = SecureRandom.hex
      options[:include_hidden] = false

      attachment_cache_field(object_name, method, object: object, **options) + file_field(object_name, method, options)
    end
Generates a form field which can be used with records which have
 attachments. This will generate both a file field as well as a hidden
 field which tracks the id of the file in the cache before it is
 permanently stored.

 @param object_name                    The name of the object to generate a field for
 @param method                         The name of the field
 @param [Hash] options
 @option options [Object] object       Set by the form builder, currently required for direct/presigned uploads to work.
 @option options [Boolean] direct      If set to true, adds the appropriate data attributes for direct uploads with refile.js.
 @option options [Boolean] presign     If set to true, adds the appropriate data attributes for presigned uploads with refile.js.
 @return [ActiveSupport::SafeBuffer]   The generated form field