Just watched and implemented the code from this screencast and it's working well. However, I realised that it only works on first page load. Subsequent pages do not run the function. Not sure if there's a bug in my code or it's because of turbolinks. Im not using bootstrap but my own implementation of an off-canvas notification (like in Macbooks).
I call all my functions in Application.js. My attempts to call the Notifications function on page change gives: "Uncaught ReferenceError: Notifications is not defined"
I'm not too versed in CoffeeScript and especially not with using classes. How do I call the Notifications function on page:change?
I'd recommend checking out jQuery.turbolinks. It's a gem that basically maps the jQuery ready function to the Turbolinks page:change function (and some others) to make all your jQuery code run as expected. It's one of those things that makes using Turbolinks a lot simpler and fixes some of the issues like this.
That should do the trick without having to write any extra code. Let me know if that works for you!
Thanks for the note Chris! Your replies alone are worth the subscription to GoRails.
Anyway never heard of the gem but I'm sure it will come it pretty handy. Will give it a try tomorrow and let you know it it works.
Thanks man! :)
I'll have to do an episode on jQuery.turbolinks soon. Also Turbolinks 5 as well since that should be coming out in the near future.
Thanks it works! Just had to edit some of the previous js code.
p.s. any plans for a yearly subscription plan?
Hope you can help.
I believe you'll have to make your CoffeeScript class global if you want to do that. More info on that: http://justinreid.com/coffeescript-global-classes/
Hey Chris! You're a beauty! After all that head banging it just took one change. Thank you so much!
Join 24,647+ developers who get early access to new screencasts, articles, guides, updates, and more.