It's been a long time since I've used Rails for the frontend of a web app, and I want to use the most update version of course, but it seems a lot has changed and I don't know which is the most Rails Way to do it anymore.
I've tried to use JQuery and the FileUpload plugin, but we don't have JQuery anymore, I mean I've tried to add it but it was a pain in the ass using the new import map (problem with me, I know if I look up some tutorials I can do i), but that seems to go agains the current mentality of JS in rails apps.
Then I've went to checkout the new Hotwire + Stimulus but I don't even now where to start, but from the little that I saw don't know if will handle this scenario: I already have a presigned_url
from my S3 Bucket
, and simply have a form with a f.file_field
which I want to upload this file from the clients browser directly to S3
doing a POST
request, so the user don't get blocked waiting the upload to finish
Correct me if I'm wrong but to trigger JS functions the Rails Way now is to use Stimulus
with HTML Data Attributes
but I'm not sure if I could pass the file in this data attribute.
Looking other tutorials I'm starting to think that the best approach would be to have a turbo_stream_tag
to wrap my form, and then when submitting the form will hit this turbo controller which will act as a ajax request, running asynchronously doing a post request using Net:HTTP
or even the s3
gem itself, I'm just not sure if I would have access to the file.
Any kind soul to clarify this? Thanks and sorry for the long post.