Sha256: b86307361cb6b11f6b1dc97cb5682b463aa214a7d0550b3b9b45c675b3b91e34

Contents?: true

Size: 821 Bytes

Versions: 5

Compression:

Stored size: 821 Bytes

Contents

module ActiveStorage
  # Temporary hack to overwrite the default file_field_tag and Form#file_field to accept a direct_upload: true option
  # that then gets replaced with a data-direct-upload-url attribute with the route prefilled.
  module FileFieldWithDirectUploadHelper
    def file_field_tag(name, options = {})
      text_field_tag(name, nil, convert_direct_upload_option_to_url(options.merge(type: :file)))
    end

    def file_field(object_name, method, options = {})
      ActionView::Helpers::Tags::FileField.new(object_name, method, self, convert_direct_upload_option_to_url(options)).render
    end

    private
      def convert_direct_upload_option_to_url(options)
        options.merge('data-direct-upload-url': options.delete(:direct_upload) ? rails_direct_uploads_url : nil).compact
      end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
activestorage_legacy-0.1.3 app/helpers/active_storage/file_field_with_direct_upload_helper.rb
activestorage_legacy-0.1.2 app/helpers/active_storage/file_field_with_direct_upload_helper.rb
activestorage_legacy-0.1.1 app/helpers/active_storage/file_field_with_direct_upload_helper.rb
activestorage_legacy-0.1.1.alpha app/helpers/active_storage/file_field_with_direct_upload_helper.rb
activestorage_legacy-0.1 app/helpers/active_storage/file_field_with_direct_upload_helper.rb