Skip to main content
Ask A Question
You’re not receiving notifications from this thread.

jquery.turbolinks not working on my app

Javascript • Asked by Enrique Benitez

I'm using both jquery and turbolinks on my app and because turbolinks don't make full page loads I need some of my js to fire when navigating between pages using turbolinks, I really don't want to use :data-no-turbolink => true because what I want to do is the same as GoRails Twitter share button on the bottom of my app pages, and if I don't do a full page refresh the Twitter widget is not going to render.

So I installed jquery.turbolinks and require it on my application.js file and that's not working, I dunno why, I even tried to do it without jquery.turbolinks by using $(document).on("ready page:load)" and inside of it the Twitter widget js code and nothing happens.

How does GoRails uses turbolinks and still renders the footer social buttons?

Any solutions?

Thanks in advance! =)

I got it working now, I used a different approach, I added <script src="//"></script> into the body, so in that way I use an external script tag within the body and now my Twitter share/follow buttons renders correctly along with turbolinks :)

Also, what stopped jquery.turbolinks and event listeners from working correctly was a different story, I got some console errors about a gem I installed, called gon, the error: gon is not defined every time I navigated from page to page using turbolinks, somehow NONE of my js code was working, I believed that was causing the problem (maybe the gon js code never terminated executing?) but I fixed it and now jquery.turbolinks and my js code is all good.

It was so simple to fix, but got my head spinning for like 5 straight hours! LOL

Thanks anyway! =)

Awesome, glad you got it working! Turbolinks can definitely be tricky to wrap your head around what's going on.

Also for reference, this is a pretty great list of solutions to convert JS from popular libraries to Turbolinks compatible stuff:

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 30,005+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.