stimulusreflex / stimulus_reflex

Build reactive applications with the Rails tooling you already know and love.
https://docs.stimulusreflex.com
MIT License
2.28k stars 172 forks source link

DirectUpload URL not set using morphs #396

Closed poqudrof closed 3 years ago

poqudrof commented 3 years ago

Hello, thanks for the great work ! 

The morphs are really amazing, even though it was already a great library.

I just found a tiny bug

Bug Report

The directUpload target is not set using morphs.

Describe the bug

The "data-direct-upload-url" is not set when using morphs.

It seems that it is done there: https://github.com/rails/rails/blob/master/actionview/lib/action_view/helpers/form_tag_helper.rb With this line: options["data-direct-upload-url"] = rails_direct_uploads_url.

I have no idea if this is normal behaviour, or if you want to add a patch to support it.

To Reproduce

Create a form with DirectUpload and render it in a morph.

Expected behavior

The URL should be (for me) localhost:5000/.... like other forms. It is http://example.com

Screenshots or reproduction

=simple_form_for experience, remote: true do |f|
  =f.input :attached_object, input_html: {"data-action" => "preview#fileSelected", direct_upload: true}
  =f.button :submit

Versions

StimulusReflex

External tools

Browser

Chrome (not the issue)

Workaround

The easiest one was to render through the controller, i.e. without morphs. It works great but I need to change some code.

Another one would be to swap the address the correct one in Javascript.

Cheers, Jeremy.

leastbad commented 3 years ago

Hello Jeremy!

SR technically doesn't support file uploads, but it shouldn't be impacting your view helpers.

Can you make sure that your environment has

  config.action_controller.default_url_options = {host: "localhost", port: 5000}

in it?

https://docs.stimulusreflex.com/deployment#set-your-default_url_options-for-each-environment

poqudrof commented 3 years ago

Hello,

It seemed that it was clearly not part of my configuration.

That fixed it. I guess you could note it in the documentation. When I searched for it I did not find any reference to the impact in DirectUpload nor the default example.org.

Thanks a lot for this quick response ! 

leastbad commented 3 years ago

I actually don't know what DirectUpload is! 🤷‍♂️

As you can see above, the information was in the docs. It's just not specific to your problem; there's no way for me to list every helper.

poqudrof commented 3 years ago

I actually don't know what DirectUpload is! man_shrugging

It is an addon for ActiveStorage to send object in Javascript directly to an object server. It features quick and easy upload progress bars, and multi-uploads.

https://edgeguides.rubyonrails.org/active_storage_overview.html#direct-uploads

Please do not be offended, I am super happy with this library and the documentation is also awesome. Indeed, it should be concise to remain clear for most users !

leastbad commented 3 years ago

Hey Jeremy, I am sorry that I can come across as prickly and overly serious in text. I want you to know that I am actually greatly relieved that we were able to come up with a quick solution to your issue, and certainly no offence was taken.

I have updated the text on the documentation to mention the example.com URL which should hopefully assist others using the search function in the future.

As a heads up, you'll get even faster replies to any problems you are having if you join the Discord! :)