Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm still a novice at both Ruby on Rails and Backbone, and I'm trying to get Backbone to work on a Rails web app. It turns out that the Turbolinks gem on my Rails app is making things just a tad more complicated.

First, I found that if you install the Turbolinks gem, you have to keep the javascript tags in the 'HEAD' section of your page. You can't keep the JS tags in 'BODY'. So of course I move the javascript tags from 'BODY' to 'HEAD'. At that point, I didn't have my Backbone code implemented.

Then, I implement my Backbone code, and I run into problems with my template code giving me a "TypeError: text is undefined" message. When I tried to figure out this problem, It turned out that you have to define your template BEFORE my javascript, not after. My template is currently defined in the HTML, and this wasn't a problem when my javascript was at the bottom of the 'BODY' section. Now it's a problem since Turbolinks is forcing me to put my javascript in the 'HEAD' section.

Is there a workaround for this, or should I just disable Turbolinks?

share|improve this question
3  
turn off turbolinks, its useful for people wanting default basic ajax. –  apneadiving Jan 8 at 18:58
1  
From doing some reading about turbolinks, I'm leaning in favor of following your advice. But for now I still want to hear from other people who might have additional arguments for or against doing this. –  drumwolf Jan 8 at 19:05
1  
turbolinks is useful (I use it heavily in some of my Rails apps) but it's very easy to conflict with and it can cause problems with other javascript. I'd agree with @apneadiving and disable it for this purpose and only use it in in situations where you are using AJAX w/o backbone. –  creativereason Jan 8 at 19:36
1  
Toss Turbolinks out, it is utterly pointless when you're building a Backbone app (or any other SPA). –  mu is too short Jan 8 at 20:10
    
Thanks to all of you who replied! Yep, Turbolinks is going out the window for this particular app. –  drumwolf Jan 8 at 20:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.