简体   繁体   English

Turbolinks不会忽略Rails应用程序中的页面

[英]Turbolinks not ignoring page in Rails app

The front page view ('Welcome/index.html.erb') : https://github.com/bfbachmann/Blog/blob/master/app/views/welcome/index.html.erb 首页视图('Welcome / index.html.erb'): https : //github.com/bfbachmann/Blog/blob/master/app/views/welcome/index.html.erb

Rails Version: 4.2.6 Rails版本: 4.2.6

The overarching problem: 首要问题:

I am trying to get my THREE.js model to show up properly inside my rails app. 我正在尝试让我的THREE.js模型正确显示在我的Rails应用程序中。 Everything works fine when I load the page by typing its URL into the search bar in my browser or if I hit reload or 'command' + R (on Windows its 'ctrl' + 'R') on my keyboard. 当我通过在浏览器的搜索栏中输入URL来加载页面时,或者在键盘上按下reload或“ command” + R(在Windows上为“ ctrl” +“ R”)时,一切正常。 I have a feeling this is because Turbolinks is not fired when these actions are performed. 我感觉这是因为执行这些操作时未触发Turbolinks。 This leaves my model in the state it should be in as shown below. 这使我的模型保持应有的状态,如下所示。

HOWEVER... when I click one of the links in the navbar (blog, projects, about etc.) and then return to the home page by clicking the house icon either the rotation speed of the model doubles, or the model is duplicated. 但是...当我单击导航栏中的链接之一(博客,项目等),然后通过单击房屋图标返回首页时,模型的旋转速度加倍,或者模型被复制。 If the model is duplicated one copy stands still while the other rotates at its regular speed as shown below. 如果复制该模型,则一个副本会静止不动,而另一个副本会以其常规速度旋转,如下所示。

Broken Version Screenshot 破解版本截图

What I've Tried 我尝试过的

I have a strong feeling Turbolinks is to blame for this. 我强烈感到Turbolinks应该为此负责。 So I tried to get Turbolinks to ignore that page by adding 'data-no-turbolink' to the body of that page... it didn't work. 因此,我试图通过在页面的正文中添加'data-no-turbolink'来使Turbolinks忽略该页面……这是行不通的。 In fact I think Turbolinks was not even ignoring the page because it still loaded much faster when I clicked the home page link than when I re-entered the page's URL. 实际上,我认为Turbolinks甚至没有忽略该页面,因为单击主页链接时,它的加载速度比重新输入页面URL时的加载速度要快得多。

I tried adding a callback that would stop all the javascript responsible for the front page from running when the user navigates away from the page. 我尝试添加一个回调,当用户离开该页面时,该回调将停止运行负责首页的所有JavaScript。 This can be found in the view I linked at the top. 可以在我顶部链接的视图中找到。 I know this callback gets fired because I tested it. 我知道此回调被触发是因为我对其进行了测试。 That also doesn't solve the problem. 那也不能解决问题。

Finally, I should also mention that I am using the JQuery-Turbolinks gem to resolve conflicts between the two. 最后,我还应该提到我正在使用JQuery-Turbolinks gem解决两者之间的冲突。

Any help would be much appreciated. 任何帮助将非常感激。 I have been trying to solve this problem for weeks. 数周以来,我一直在努力解决这个问题。

Edit: I forgot to mention that I have read that Turbolinks has problems with inline javascript... this could be causing that problem. 编辑:我忘了提到我已经阅读了Turbolinks内联javascript的问题...这可能是导致该问题的原因。

Edit: It appears my javascript is being run every time I load ANY page on my site even though it is inline javascript. 编辑:每次我在网站上加载任何页面时,即使它是嵌入式javascript,我的javascript都在运行。 I can't understand why. 我不明白为什么。

It turns out I was right. 原来我是对的。 Turbolinks was not ignoring that page because I did not tell it to do so correctly. Turbolinks没有忽略该页面,因为我没有告诉它正确执行此操作。

Originally I had 'data-no-turbolink=true' in the body of the page that was causing problems. 最初,我在导致问题的页面正文中使用“ data-no-turbolink = true”。 It turns out that the correct way to do it is to add 'data-turbolinks=false' as stated in the rails official documentation here . 事实证明,这样做正确的方法是作为官方文档中轨规定添加“数据turbolinks =假” 在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM