diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-07-31 15:21:22 -0400 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-07-31 15:21:22 -0400 |
commit | 9330d01ada9ce6768d14c59b99cd3860e209737a (patch) | |
tree | e4328b4e59b52dae35241f835f786641d1ff8595 /activestorage/app/helpers | |
parent | 0d58e7e478e79c2d6b2a39a4444d2a17a903b2a6 (diff) | |
parent | 3f4a7218a4a4923a0e7ce1b2eb0d2888ce30da58 (diff) | |
download | rails-9330d01ada9ce6768d14c59b99cd3860e209737a.tar.gz rails-9330d01ada9ce6768d14c59b99cd3860e209737a.tar.bz2 rails-9330d01ada9ce6768d14c59b99cd3860e209737a.zip |
Add 'activestorage/' from commit '3f4a7218a4a4923a0e7ce1b2eb0d2888ce30da58'
git-subtree-dir: activestorage
git-subtree-mainline: 0d58e7e478e79c2d6b2a39a4444d2a17a903b2a6
git-subtree-split: 3f4a7218a4a4923a0e7ce1b2eb0d2888ce30da58
Diffstat (limited to 'activestorage/app/helpers')
-rw-r--r-- | activestorage/app/helpers/active_storage/file_field_with_direct_upload_helper.rb | 18 |
1 files changed, 18 insertions, 0 deletions
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 new file mode 100644 index 0000000000..7c5fd0eb55 --- /dev/null +++ b/activestorage/app/helpers/active_storage/file_field_with_direct_upload_helper.rb @@ -0,0 +1,18 @@ +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 |