Maestro
Maestro

Reputation: 75

Rails 3.2.2 actions are being called twice

My app is based on Rails 3.2.2. Faced some strange problem: all actions in development/production are called twice. Any suggestions?

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)

Updated #1

Simple controller:

class FaqsController < ApplicationController
  respond_to :html

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

View is quite simple too:

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

Upvotes: 2

Views: 1144

Answers (2)

engineerDave
engineerDave

Reputation: 3935

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.

Upvotes: 2

barelyknown
barelyknown

Reputation: 5560

This issue probably does not have anything to do with Rails 3.2.2.

This exact behavior would be seen if you had javascript on your pages that was making an ajax request when the page was loaded. I would walk through all of your script assets and look for one that is meant to call back to your app after the page is loaded. You'll probably find the culprit there.

Upvotes: 0

Related Questions