Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable TurboLinks in Rails 6?

So I'm facing this problem where my server does actually retrieve the correct data from the client's request, sending this data to the browser where I can clearly see that its avaible for the browser (CTRL+SHIFT+C > Network > my_request). However, the browser doesn't refresh. So I'm now seeing the previous page's data. After searching for a bit, I determined it was caused by TurboLinks which I then tried to disable as done here or here. Yet the browser still won't refresh and show up the newly fetched data. The last thing I did was grep -r turbolink * in my project directory which gave me the following:

app/views/layouts/_dashboard_menu_certified.html.erb:          <%= submit_tag("Apply", {'data-turbolinks': false}) %>
log/development.log:    21:     <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
node_modules/@rails/webpacker/README.md:<%= javascript_packs_with_chunks_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %>
node_modules/@rails/webpacker/README.md:<script src="/packs/vendor-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
node_modules/@rails/webpacker/README.md:<script src="/packs/calendar~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
node_modules/@rails/webpacker/README.md:<script src="/packs/calendar-1016838bab065ae1e314.js" data-turbolinks-track="reload"></script>
node_modules/@rails/webpacker/README.md:<script src="/packs/map~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
node_modules/@rails/webpacker/README.md:<script src="/packs/map-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
node_modules/@rails/webpacker/CHANGELOG.md:<%= stylesheet_packs_with_chunks_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %>
node_modules/@rails/webpacker/CHANGELOG.md:<%= javascript_packs_with_chunks_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %>
node_modules/@rails/webpacker/CHANGELOG.md:<script src="/packs/vendor-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
node_modules/@rails/webpacker/CHANGELOG.md:<script src="/packs/calendar~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
node_modules/@rails/webpacker/CHANGELOG.md:<script src="/packs/calendar-1016838bab065ae1e314.js" data-turbolinks-track="reload"></script>
node_modules/@rails/webpacker/CHANGELOG.md:<script src="/packs/map~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
node_modules/@rails/webpacker/CHANGELOG.md:<script src="/packs/map-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>

Is there something I missed ? Cheers.

EDIT:

<div class="col-sm-6 card">
      <% @res.each do |tool, histories| %>
        <div class="chart">
          <div class="card-header">
            <div class="nav nav-pills card-header-pills">
              <%= tool %>
            </div>
          </div>
          <div class="card-body">
            <div id="<%= tool %>" class=""></div>
            <script>
              new Morris.Line({
              element: "<%= tool %>",
              data: [
                <% histories.each do |history| %>
                  { date: '<%= history.date %>', value: <%= history.uptodate %>, value2: <%= history.outdated %>, value3: <%= history.error %>},
                <% end %>
              ],
              xkey: 'date',
              ykeys: ['value', 'value2', 'value3'],
              labels: ['UpToDate', 'OutDated', 'Error']
              })
            </script>
          </div>
        </div>
      <% end %>
</div>
like image 679
HCKRMVT Avatar asked Dec 12 '19 13:12

HCKRMVT


1 Answers

  1. Remove gem 'turbolinks', '~> 5' from Gemfile
  2. Remove //= require turbolinks from app/assets/javascript/application.js
  3. Remove , 'data-turbolinks-track': 'reload' (x2) from app/views/layouts/application.html.erb
  4. Run yarn remove turbolinks
  5. Run rails tmp:cache:clear

Step 4 is the main difference with Rails 5.

like image 169
Luis M Rodriguez-R Avatar answered Sep 28 '22 18:09

Luis M Rodriguez-R