diff options
3 files changed, 10 insertions, 20 deletions
diff --git a/actionview/lib/action_view/helpers/form_helper.rb b/actionview/lib/action_view/helpers/form_helper.rb index 4eac086a87..314a2e3f44 100644 --- a/actionview/lib/action_view/helpers/form_helper.rb +++ b/actionview/lib/action_view/helpers/form_helper.rb @@ -1193,7 +1193,7 @@ module ActionView # file_field(:attachment, :file, class: 'file_input') # # => <input type="file" id="attachment_file" name="attachment[file]" class="file_input" /> def file_field(object_name, method, options = {}) - Tags::FileField.new(object_name, method, self, options).render + Tags::FileField.new(object_name, method, self, convert_direct_upload_option_to_url(options)).render end # Returns a textarea opening and closing tag set tailored for accessing a specified attribute (identified by +method+) @@ -2316,6 +2316,10 @@ module ActionView options[:include_id] = !options.delete(:skip_id) end end + + 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 diff --git a/actionview/lib/action_view/helpers/form_tag_helper.rb b/actionview/lib/action_view/helpers/form_tag_helper.rb index 91046acbf8..83b600d871 100644 --- a/actionview/lib/action_view/helpers/form_tag_helper.rb +++ b/actionview/lib/action_view/helpers/form_tag_helper.rb @@ -274,7 +274,7 @@ module ActionView # file_field_tag 'file', accept: 'text/html', class: 'upload', value: 'index.html' # # => <input accept="text/html" class="upload" id="file" name="file" type="file" value="index.html" /> def file_field_tag(name, options = {}) - text_field_tag(name, nil, options.merge(type: :file)) + text_field_tag(name, nil, convert_direct_upload_option_to_url(options.merge(type: :file))) end # Creates a password field, a masked text field that will hide the users input behind a mask character. @@ -904,6 +904,10 @@ module ActionView tag_options.delete("data-disable-with") end + + 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 end diff --git a/activestorage/app/helpers/active_storage/file_field_with_direct_upload_helper.rb b/activestorage/app/helpers/active_storage/file_field_with_direct_upload_helper.rb deleted file mode 100644 index 7c5fd0eb55..0000000000 --- a/activestorage/app/helpers/active_storage/file_field_with_direct_upload_helper.rb +++ /dev/null @@ -1,18 +0,0 @@ -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 |