代码之家  ›  专栏  ›  技术社区  ›  gabrielhilal

Zurb基金会正在使我的资产加载两次

  •  3
  • gabrielhilal  · 技术社区  · 11 年前

    应用程序.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" %> 到顶部,但导航菜单不起作用。

    知道吗?

    2 回复  |  直到 11 年前
        1
  •  2
  •   Mike Szyndel    11 年前

    要使导航正常工作,请尝试添加 gem 'jquery-turbolinks' 给你 Gemfile 然后添加 //= require jquery.turbolinks 到您的application.js-这应该会处理应用程序中的所有$(document).ready绑定。

    然后将您的javascript标记移回头部。

    顺便说一句,服务器似乎同时收到了两个请求(例如,来自浏览器中两个交付的选项卡),也可能是这样。

        2
  •  0
  •   Ryan.lay    11 年前

    我在双服务器日志方面也遇到了同样的问题,结果发现这是Rails STDOUT记录器的问题。

    查看以下链接:

    A log that looks exactly like yours

    Issue tracked here

    使用Chrome查看您的页面请求时间表。如果您的页面的资产只加载了一次,而被记录了两次,那么这很可能是同一个问题。