Foundation 5 Topbar 在 Rails 4 中无法始终如一地工作 [英] Foundation 5 Topbar not working consistently in rails 4

查看:24
本文介绍了Foundation 5 Topbar 在 Rails 4 中无法始终如一地工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 rails 4 应用程序中使用基础 5.当我发送请求时,顶栏菜单工作正常.我可以悬停项目和嵌套项目没有问题.然后,我单击其中一个项目,该项目有一个关联的 link_to 方法.有时它会给出正确的结果,我的菜单仍然可以完美运行,但有时整个事情都会冻结.这也让手机菜单的后退按钮消失了.一旦我通过刷新或 url 发送新请求,菜单就会再次工作.

I'm using foundation 5 in my rails 4 app. The topbar menu works fine when I send a request. I can hover the items and nested items no problems. Then, I click on one of the items, which has a link_to method associated to it. Sometimes it gives the proper result where my menu still works perfectly, but other times the whole thing freezes. This also makes the back button of the mobile menu disappear. Once I send a new request through the refresh or url, the menu works again.

Rails 在日志文件中没有发现任何问题.我的菜单在导轨外运行良好.我想知道这是否与我的 link_to tag_helpers 或我在应用中设置基础的方式有关?

Rails doesn't see any problem in the log file. My menu works fine outside of rails. I wonder if maybe it has to do with my link_to tag_helpers or the way I have set up foundation in my app?

这里是关于如何为基础路由 JS 的快速概述.(他们在文档中建议的配置)视图/布局/application.html.erb:

Here is a quick overview on how the JS is routed for foundation. (The config they suggest on their docs) views/layouts/application.html.erb:

<head>
 <meta name="viewport" content="width=device-width, initial-scale=1.0" />
 <%= stylesheet_link_tag    "application" %>
 <%= javascript_include_tag "vendor/modernizr" %>
</head>   
<body>     
  <%= javascript_include_tag "application" %>     
</body>

assets/application.js:

assets/application.js:

//= require jquery
//= require jquery_ujs
//= require foundation
//= require turbolinks
//= require_tree .

$(document).foundation();

有没有其他人遇到过这个问题?除了不使用基础 5 之外,还有什么好的解决方案吗?

Has anybody else encountered this problem? Any good solution other than not using foundation 5 out there?

谢谢亚历克斯

推荐答案

Foundation 有已知的 Turbolinks 问题,您的问题可能是由该问题引起的.

Foundation has known issues with Turbolinks, your issue may be due to that.

要解决此问题,您可以禁用 Turbolinks 并查看顶部栏是否仍然存在问题.

To troubleshoot that, you could disable Turbolinks and see if the top-bar still has issues.

这是一个简单的指南:http://blog.steveklabnik.com/posts/2013-06-25-removing-turbolinks-from-rails-4.

Here's a simple guide: http://blog.steveklabnik.com/posts/2013-06-25-removing-turbolinks-from-rails-4 .

除此之外,如果您必须拥有 Turbolinks,Turbolinks 就是问题所在.您可以尝试添加 jquery turbolinks,如下所示:https://github.com/kossnocorp/jquery.turbolinks .

Beyond that, if you must have Turbolinks, and Turbolinks is the issue. You can try adding jquery turbolinks as seen here: https://github.com/kossnocorp/jquery.turbolinks .

如果问题仍然存在,下一步将是检查您导入 javascript 文件的顺序(这与这些 Turbolinks/Foundation 问题有关),您可能会满意这种方式. 我没有确切的顺序让你把它们放进去,但如果你搜索Turbolinks Foundation"问题,你最终会偶然发现一些解决方案.这不一定是一个特定的解决方案,但它'将引导您朝着正确的方向前进.

If the problem continues to persist, the next step would be to check the order you're importing the javascript files (this matters with these Turbolinks / Foundation issues) and you may be satisfied that way. I do not have an exact order for you to put them in, but if you search for "Turbolinks Foundation" issues you will eventually stumble onto some solutions. This is not necessarily a certain solution, but it'll guide you in the right direction.

更新:尝试使用此命令导入您的 javascript 资产.而且,引用来源:

Update: Try this order for importing your javascript assets. And, to quote the source:

将所有要加载的 Javascript 放在标签内很重要.包含 jQuery 的顺序很重要——确保在 turbolinks 之前和 jquery 之后加载 jquery.turbolinks.在 application.js 中包含 jquery-turbolinks.js 和 turbolinks.js 之间的所有自定义 js
Its important to put all the Javascripts to be loaded inside the tag. The order of inclusion of jQuery is important – ensure you load jquery.turbolinks before turbolinks and after jquery. Include all your custom js between jquery-turbolinks.js and turbolinks.js in your application.js

// app/assets/javascript/application.js

//= require jquery
//= require jquery.turbolinks
//= require jquery_ujs

//= require foundation
//= require jwplayer/jwplayer.js
//= require asset_videos

//= require turbolinks

注意:查看此页面上的Alex Aube 的回答,了解更多有用信息.

Note: Look at Alex Aube's answer on this page for additional useful information.

这篇关于Foundation 5 Topbar 在 Rails 4 中无法始终如一地工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆