I'm using Rails 7 with Turbo. I'm trying to build a file upload mechanism - the idea is that user in the profile page could upload the file and after upload success, page should not be reloaded but it should show a green mark as a success confirmation.
My code:
# routes
kyc_document_upload POST /kyc_document_upload(.:format) profile#kyc_document_upload
# profile_controller.rb
class ProfileController < ApplicationController
def kyc_document_upload
@file = FileRead.read(params[:file])
body = Base64.encode64(@file)
ExternalApi.user.sent_missing_docs(body)
end
# views/profile/show.html.erb
<%= form_tag(kyc_document_upload_path, multipart: true) do %>
<%= file_field_tag "file" %>
<%= submit_tag %>
<% end %>
How to add turbo and green mark instead of redirection ?
I think it's not relevant but worth to mention that the file itself is not saved anywhere but is encoded into Base64 string and sends this file to an external service under the hood.