2

我的应用程序基于Rails 3.2.2.面临一些奇怪的问题:开发/生产中的所有操作都被调用了两次。有什么建议么?

Started GET "/faqs" for 127.0.0.1 at 2012-07-07 17:08:06 +0200
Processing by FaqsController#index as HTML
  Faq Load (0.5ms)  SELECT `faqs`.* FROM `faqs` WHERE `faqs`.`active` = 1 ORDER BY position asc
  Rendered faqs/index.html.haml within layouts/application (3.1ms)
  Rendered shared/_navigation_bar.html.haml (5.3ms)
  Rendered devise/registrations/_register.html.erb (5.5ms)
Completed 200 OK in 137ms (Views: 43.3ms | ActiveRecord: 0.5ms | Solr: 0.0ms)


Started GET "/faqs" for 127.0.0.1 at 2012-07-07 17:08:06 +0200
Processing by FaqsController#index as */*
  Faq Load (0.2ms)  SELECT `faqs`.* FROM `faqs` WHERE `faqs`.`active` = 1 ORDER BY position asc
  Rendered faqs/index.html.haml within layouts/application (0.2ms)
  Rendered shared/_navigation_bar.html.haml (3.9ms)
  Rendered devise/registrations/_register.html.erb (12.1ms)
Completed 200 OK in 33ms (Views: 30.2ms | ActiveRecord: 0.2ms | Solr: 0.0ms)

更新#1

简单的控制器:

class FaqsController < ApplicationController
  respond_to :html

  def index
    @faqs = Faq.all
    respond_with(@faqs)
  end
end

视图也很简单:

%h2 Faqs
- @faqs.each_with_index do |faq, index|
  .span9  
    %h3
      = "%d." % (index + 1)
      = faq.title
    %p= faq.body
4

2 回答 2

2

This is probably due to Chrome. You can test in Safari/Firefox/IE etc

The reason I believe it causes two loads is because Chrome "forks" the request and essentially makes two requests. It renders the first one that returns in its window.

IIRC I researched this many years ago and this was a feature implemented to render pages faster.

于 2014-08-13T17:10:43.380 回答
0

这个问题可能与 Rails 3.2.2 没有任何关系。

如果您的页面上有 javascript 在页面加载时发出 ajax 请求,就会看到这种确切的行为。我将遍历您的所有脚本资产,并寻找一个旨在在页面加载后回调您的应用程序的脚本资产。你可能会在那里找到罪魁祸首。

于 2013-01-27T17:58:27.983 回答