Question

I have a legacy project in Rails 3. While upgrading to Rails 4, I wanted to test out turbo links, but can not seem to get it working. I have added the 'turbolinks' gem to the Gemfile, bundle install, and added //= require turbolinks to app/assets/javascripts/application.js, and restarted the server.

All pages still do full page refreshes, as observed from the network requests activity in Chrome.

Edit: I followed the small Turbolinks test suggested in one of the answers. I added a blank demo controller, and page1, page2 views. If Turbolinks were working properly, turbolinks should be seen as the initiator in network requests, and test.js should not be loaded.

The small example fails, because test.js is attempting to load, there is a full page refresh, and the initiator is still not turbolinks.

page1.html.erb

<html>
  <title>Page 1</title>
  <body>
    <h1>Page 1</h1>
    <a href="/test_turbo/page2">Page 2</a>
  </body>
</html>

page2.html.erb

<html>
  <title>Page 2</title>
  <script type="text/javascript" src="test.js"></script>
  <body>
    <h1>Page 2</h1>
  </body>
</html>
Was it helpful?

Solution

Check out this Turbolinks screencast.

The entire page is still rendered and returned to the browser, but only the body is replaced.

You can check to make sure they are working by having two pages. Page 2 should load, but when you inspect the header of the page it should NOT include the test javascript file. Let us know if it still isn't working.

Page 1

<html>
  <title>Page 1</title>
  <body>
    <h1>Page 1</h1>
    <a href="/page2">Page 2</a>
  </body>
</html>

Page 2

<html>
  <title>Page 2</title>
  <script type="text/javascript" src="test.js"></script>
  <body>
    <h1>Page 2</h1>
  </body>
</html>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top