应用程序.css:
*= require_self
*= require foundation_and_overrides
*= require_tree .
*/
应用程序.js:
*= require jquery
*= require jquery_ujs
*= require foundation
*= require jquery_nested_form
*= require highcharts/highcharts
*= require turbolinks
*= require_tree .
$(function(){ $(document).foundation(); });
Application.html.erb(由基金会生成):
<!DOCTYPE html>
<!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ -->
<!--[if lt IE 7 ]> <html class="ie6" lang="en"> <![endif]-->
<!--[if IE 7 ]> <html class="ie7" lang="en"> <![endif]-->
<!--[if IE 8 ]> <html class="ie8" lang="en"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--> <html lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8" />
<!-- Uncomment to make IE8 render like IE7 -->
<!-- <meta http-equiv="X-UA-Compatible" content="IE=7" /> -->
<!-- Set the viewport width to device width for mobile -->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title><%= content_for?(:title) ? yield(:title) : "Untitled" %></title>
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "vendor/custom.modernizr" %>
<%= csrf_meta_tags %>
</head>
<body>
<header>
<nav class="top-bar">
<%= render 'layouts/nav' %>
</nav>
<%= render 'layouts/flash' %>
</header>
<section>
<%= yield %>
</section>
<footer>
<%= render 'layouts/footer' %>
</footer>
<%= javascript_include_tag "application" %>
</body>
</html>
开发日志:
Started GET "/" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Processing by UsersController#show as HTML
Processing by UsersController#show as HTML
Rendered users/show.html.erb within layouts/application (0.1ms)
Rendered users/show.html.erb within layouts/application (0.1ms)
Rendered layouts/nav/_director.html.erb (0.6ms)
Rendered layouts/nav/_director.html.erb (0.6ms)
Rendered layouts/nav/_manager.html.erb (0.4ms)
Rendered layouts/nav/_manager.html.erb (0.4ms)
Rendered layouts/nav/_supervisor.html.erb (0.2ms)
Rendered layouts/nav/_supervisor.html.erb (0.2ms)
Rendered layouts/_nav.html.erb (3.2ms)
Rendered layouts/_nav.html.erb (3.2ms)
Rendered layouts/_flash.html.erb (0.1ms)
Rendered layouts/_flash.html.erb (0.1ms)
Rendered layouts/_footer.html.erb (0.1ms)
Rendered layouts/_footer.html.erb (0.1ms)
Completed 200 OK in 14ms (Views: 12.7ms | ActiveRecord: 0.3ms)
Completed 200 OK in 14ms (Views: 12.7ms | ActiveRecord: 0.3ms)
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.alerts.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.alerts.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.dropdown.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.dropdown.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.forms.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.forms.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.joyride.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.joyride.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.clearing.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.clearing.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.magellan.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.magellan.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.orbit.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.orbit.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.reveal.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.reveal.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.section.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.section.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.cookie.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.cookie.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.topbar.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.topbar.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.interchange.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.interchange.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.tooltips.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.tooltips.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.placeholder.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.placeholder.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.abide.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/foundation.abide.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/jquery_nested_form.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/jquery_nested_form.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/index.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/foundation/index.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/highcharts/highcharts.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/highcharts/highcharts.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/turbolinks.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/turbolinks.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2013-08-30 13:27:35 +0100
正如您所看到的,它加载每个资源两次。此外,我正在使用nested_form
,因此当我单击添加嵌套表单时,它会添加许多表单,而不仅仅是一个。
但是,如果我刷新页面,表单就会按预期工作。
我尝试过设置 <%= javascript_include_tag "application" %>
模式到顶部,但导航菜单不起作用。
有什么想法吗?
最佳答案
要使导航正常工作,请尝试将 gem 'jquery-turbolinks'
添加到 Gemfile
中,然后添加 //= require jquery.turbolinks
到您的 application.js - 应该处理应用程序中的所有 $(document).ready 绑定(bind)。
然后将您的 javascript 标记移回头部。
而且,顺便说一句,服务器似乎同时收到 2 个请求(例如,来自浏览器中的 2 个 livereloaded 选项卡),情况也可能如此。
关于jquery - Zurb 基金会正在让我的 Assets 加载两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18533070/