9

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>
HCKRMVT
  • 355
  • 3
  • 10
  • Please explain: do you click a link to start the action to retrieve the new data? Is it some javascript code? How does your controller code look? What are you rendering (a full page-view, a partial, how do you update part of the screen?), which rails version are you using? – nathanvda Dec 12 '19 at 14:00
  • I have this ```<%= form_with(url: "my_controller", method: "get") do %>``` with a ```<%= submit_tag("Apply", {'data-turbolinks': false}) %>```. So the submit_tag is the one that triggers the query and thus the controller that either fills an array with the corresponding data or render's a template if the query from the form wasn't valid. What I'm rendering is a partial page where the newly fetched data should be displayed. As the question says, i'm running rails 6. – HCKRMVT Dec 12 '19 at 14:20
  • So if the data is valid, it fills an array, and how do you render/return this? It should still render a view to return the data. Can you show us that view? Are you using some kind of javascript framework to render the array/list client-side? – nathanvda Dec 12 '19 at 14:51
  • I render it the same way as the previous page with the previous data. And yes, I'm using Morris.js to create chart out of the data. – HCKRMVT Dec 12 '19 at 15:02
  • 1
    Right, you say this as if I know what you mean with "the previous page with the previous data". Is that another form? Another page with another form? Have you got another page with a `form_with` that works? Then look for the differences? `form_with` is by default `remote`, maybe you need to add the option `local: true` ? – nathanvda Dec 13 '19 at 09:03
  • The form is the same, it comes from the same page / view. What would changing ```remote``` to ```local: true```, I can quite get the documentation. – HCKRMVT Dec 16 '19 at 09:39

1 Answers1

17
  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.

Luis M Rodriguez-R
  • 1,212
  • 11
  • 10
  • 7
    Or with webpacker, comment out `require("turbolinks").start()` in `app/javascript/packs/application.js` – Hari Honor Aug 07 '20 at 13:00
  • 2
    Just a reminder to run `bundle install` afterwards so that any `Gemfile.lock` or similar gets updated – stevec Oct 07 '20 at 01:35