"Content missing" Ruby on Rails, Turbo issue

2 weeks ago 28
ARTICLE AD BOX

I have turbo rails built into my ruby on rails application, I have a section of the screen I am trying to reload with a button click. more specifically a directory tree. But every time I click said button the only thing the turbo-frame will show is "Content missing". it's important to note that when the request is made, a response is received immediately after the code is finished but the response body remains empty for a few seconds before catching up (in my test case the response body is 26k lines).

Question: how can I ask turbo to wait until the response has a body to change the frame?
Question: What other tools in ruby-on-rails can I use to do this?
Question: How can I optimize the code I generate to lower the number of lines it needs to load?

Bellow is the code I use run everything:
main_controller.rb:

def refresh_tree root_directory_path = Dir.home @tree = directory_tree(root_directory_path) render partial: "shared/directory_tree", locals: { tree: @tree, id: Dir.home.gsub('/', '_') } end

index.html.erb:

<div class="sidebar-header"> <h3>Directory Tree</h3> <%= button_to raw('<i class="fas fa-sync-alt"></i> Refresh'), "/refresh_tree", method: :get, class: "btn btn-sm btn-outline-secondary", form: { data: { turbo_frame: "directory-tree" } } %> </div> <%= turbo_frame_tag "directory-tree", class: "directory-tree" do %> <h1> FILLER CODE </h1> <% end %>

shared/_directory_tree.html.erb:

<ul class="directory-tree" id="<%= id %>"> <% tree.each do |item| %> <li style="display: none; list-style-type: none; white-space: nowrap;" class="<%= item[:type] %>"> <% if item[:type] == 'directory' %> <%# DIRECTORIES GO HERE %> <svg class="clickable-arrow" width="12" height="12" viewBox="0 0 12 12" onclick="toggleListItems(`<%= item[:item_path].gsub('/', '_') %>`); toggleArrow(this);"> <path d="M4 2 L8 6 L4 10" stroke="#8a8a8a" stroke-width="1.5" fill="none" stroke-linecap="round" stroke-linejoin="round" /> </svg> <%= button_to item[:name], "/folder", method: :get, params: { item_path: item[:item_path] }, class: "btn btn-plain-text name text-nowrap", form: { data: { turbo_frame: "file-grid" } } %> <%= render 'shared/directory_tree', tree: item[:children], id: item[:item_path].gsub('/', '_') %> <% else %> <%# FILES GO HERE %> <%= button_to item[:name], "/file", method: :get, params: { item_path: item[:item_path] }, class: "btn btn-plain-text name text-nowrap", form: { data: { turbo_frame: "file-grid" } } %> <% end %> </li> <% end %> </ul>
Read Entire Article