bundle to install it, and then we'll go to our application.js file and add that in. You say:
//require jquery-turbolinks in order to do that. You want to do this before turbolinks runs, and this will basically just do everything that you need in order to get your normal jQuery code rerunning on every page. This code will be rerun every time, whereas it wouldn't if it didn't have the jQuery turbolinks. Let's refresh this page, we'll see it of course works the first time, but that always works with turbolinks, and it's the second time that it doesn't normally work, but it does. That jQuery turbolinks gem basically adds this jQuery turbolinks file. There's a really short amount of code that basically says: This load and fetch events, we need to integrate with jQuery and make sure that they rerun along turbolinks. This is great, but we have to see if it's also going to be compatible with the new turbolinks 5.0. There's a beta version of the gem out there, which you can grab, you can install that into your application by overriding your gem turbolinks line, and specifying that it needs to be the beta version of 5.0 or higher, and if you can go back to your terminal, and run
bundle to install that, and just to note here, I originally had this line in, but for whatever reason, that wasn't working, and I had to change it to use that format for the version number, and then running
That's really it for upgrading to turbolinks 5 from version 2.5. If you're on version 3, of course I didn't mention that if you do use partial replacements, you're going to want to change that code so that it doesn't do that. The reason for that is because the turbolinks 5 gem doesn't support that, and we'll get marginal benefits from it anyways, so it should simplify and standardize your code a lot better to remove that.
Last but not least is this Android and iOS wrappers, hopefully they will get released soon, they're still not out yet, but I plan on doing an episode shortly after they get released, because that is going to be kind of the killer feature of this, being able to do all of this together. It wasn't the most complicated episode, but at the same time, it's pretty impressive that an upgrade from turbolinks 2.5 to 5.0 is just going to simply be including this compatibility file for the time being, and I'm sure we'll see jQuery.turbolinks get upgraded to use these new events, but until then you don't even have to worry about that, and you should be fine operating with the compatibility file until then.
That's it for this episode, and I will talk to you next week. Peace
Hi Chris, great episode! You can also skip the extra gem(s) and compatibility files by simply changing code. Doing something like:
Old Turbolinks Classic:
$(document).on "ready page:load", ->
# CoffeeScript code
$(document).on "turbolinks:load", ->
# CoffeeScript code
Thanks for the great video Chris!
I keep getting an error though:
I think some things have changed since your video, like the compatibility file name, but other than that, I followed your video exactly.
The error is being raised in my application.html.erb. Also, I'm using turbolinks-source 5.0.0.beta2
The turbolinks/compatibility.coffee file doesn't ship with the gem unfortunately (at least not right now). You'll have to copy it into your Rails app from the original repo. I've got a link to it in the resources section above, but here's the link as well: https://github.com/turbolin... Paste that into your Rails app and just require the file like normal and you should be set.
Wow, thanks for the quick response!
Do you think something has changed from beta1 one to beta2 that's causing the problem?
I don't believe so. It sounds like the normal error you get when trying to require a file that doesn't exist, although you have created it locally it sounds like. Possibly a typo in your filename?
Oh man! In an effort to avoid any spelling errors I copied and pasted the file name from the repo. The only problem is I copied an extra space at the end of the name so the file names didn't match up and I couldn't see it until I highlighted the file name! DOH!
Thanks for your help Chris! You're the man!
Ha, wow that's a subtle one. You'd think that it would automatically strip out spaces at the end of the filename by 2016. ;)
Hey chris, I'd like to build up product associations in the products edit view using modals. ie generating a specs table.
When i submit a form to the create action it re renders and closes the modal. adding data-turbolinks-permanent doesn't seem to solve the problem as the new specs won't show up
This form would be rather long for one page, is it possible to accomplish what I'm trying to do with turbolinks 5 or should I look to do something like breaking the form out into separate pages?
It sounds like potentially what you want is the "remote: true" AJAX requests so that you can handle things on your own. Turbolinks won't really do anything here because the form is going to submit a POST and Turbolinks can only really handle GET requests. That's the main reason it's not going to be a good solution for your problem. I think using a JS response to the form submit should give you a lot more flexibility to do what you want there.
Hey Chris, I've been having trouble with turbo links. I'm not planning to upgrade my turbolinks and I have the jquery.turbolinks gem installed. The problem is that on first load my subscriptions_new submit button won't fire. It fires once I reload the page and everything works fine then. Any suggestions?
Never mind. Comment removed.
Having issue with Rails 5 and Turbolinks. I have added the jquery-turbolinks gem and still having issues.
//= require jquery
//= require jquery.turbolinks
//= require jquery_ujs
//= require tether
//= require bootstrap-sprockets
//= require bootstrap-datepicker/core
//= require_tree .
//= require turbolinks