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

时间:2021-10-19 15:16:28

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. 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. I have a feeling this is because Turbolinks is not fired when these actions are performed. This leaves my model in the state it should be in as shown below.

我想让我的THREE.js模型在我的rails应用程序中正确显示。当我通过在浏览器的搜索栏中输入其URL来加载页面或者我在键盘上点击重新加载或“命令”+ R(在Windows上它的'ctrl'+'R')时,一切正常。我有一种感觉,这是因为在执行这些操作时不会触发Turbolinks。这使我的模型处于应该处于的状态,如下所示。

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. 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. 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应该归咎于此。因此,我试图让Turbolinks忽略该页面,将“data-no-turbolink”添加到该页面的主体......它没有用。事实上,我认为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. 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.

我尝试添加一个回调,当用户导航离开页面时,该回调将阻止负责首页的所有javascript运行。这可以在我在顶部链接的视图中找到。我知道这个回调被解雇了,因为我测试了它。这也无法解决问题。

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. I can't understand why.

编辑:每次我在我的网站上加载任何页面时都会运行我的javascript,即使它是内联javascript。我不明白为什么。

1 个解决方案

#1


0  

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. It turns out that the correct way to do it is to add 'data-turbolinks=false' as stated in the rails official documentation here.

最初我在页面正文中有'data-no-turbolink = true'导致问题。事实证明,正确的方法是添加'data-turbolinks = false',如rails官方文档中所述。

#1


0  

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. It turns out that the correct way to do it is to add 'data-turbolinks=false' as stated in the rails official documentation here.

最初我在页面正文中有'data-no-turbolink = true'导致问题。事实证明,正确的方法是添加'data-turbolinks = false',如rails官方文档中所述。