get リクエストが 2 回呼び出されるという奇妙な問題があります。ここにログ出力があります
最初の呼び出し
Started GET "/admin/dashboard" for 127.0.0.1 at 2013-02-14 17:42:33 -0500
Processing by Admin::DashboardController#index as HTML
直後の2回目の電話
Started GET "/admin/dashboard" for 127.0.0.1 at 2013-02-14 17:42:34 -0500
Processing by Admin::DashboardController#index as */*
ここに私のルート出力があります
admin_dashboard_index GET /admin/dashboard(.:format) admin/dashboard#index
POST /admin/dashboard(.:format) admin/dashboard#create
new_admin_dashboard GET /admin/dashboard/new(.:format) admin/dashboard#new
edit_admin_dashboard GET /admin/dashboard/:id/edit(.:format) admin/dashboard#edit
admin_dashboard GET /admin/dashboard/:id(.:format) admin/dashboard#show
PUT /admin/dashboard/:id(.:format) admin/dashboard#update
DELETE /admin/dashboard/:id(.:format) admin/dashboard#destroy
そして私のroutes.rb
namespace :admin do
resources :pages do
member do
get 'visual'
end
end
resources :dashboard, :posts, :help
end
これは正常ですか?これは開発と製品の両方で発生し、その結果、各 GET 呼び出しもデータベース クエリを作成しています。
更新: コントローラー出力の追加
ここに私の admin/dashboard_controller があります
class Admin::DashboardController < AdminController
def index
@authentications = current_user.authentications
@has_facebook = @authentications.find_by_provider(:facebook)
if @has_facebook
@fb_me = FbGraph::User.me(@has_facebook.token)
@fb_me.fetch
end
end
そして私のadmin_controller
class AdminController < ApplicationController
before_filter :authenticate_user!
layout "admin/layouts/application"
end
end
そして私のapplication_controller:
class ApplicationController < ActionController::Base
before_filter :set_locale
before_filter :set_company
before_filter :subdomain_view_path
protect_from_forgery
prepend_view_path "app/views/admin"
rescue_from CanCan::AccessDenied do |exception|
redirect_to root_path, :alert => exception.message
end
rescue_from ActiveRecord::RecordNotFound do |exception|
redirect_to root_path, :alert => exception.message
end
def set_locale
I18n.locale = I18n.default_locale
end
def set_company
if current_user
@current_account = current_user.company
return
end
if request.subdomain.present? and request.subdomain != 'www'
@current_account = Company.find_by_subdomain(request.subdomain)
else
if request.domain.present?
@current_account = Company.find_by_subdomain(request.domain.split('.')[0])
end
end
if not @current_account
@current_account = Company.find_by_subdomain('default')
end
end
def subdomain_view_path
if request.subdomain.present? and request.subdomain != 'www'
prepend_view_path "app/views/#{request.subdomain}_subdomain"
else
if request.domain.present?
prepend_view_path "app/views/#{request.domain.split('.')[0]}_subdomain"
else
prepend_view_path "app/views/default_subdomain"
end
end
end
def check_addon_product
if @current_account.addons.find_by_title('products')
return true
else
redirect_to root_path, :alert => "Products addon not enabled for this account."
end
end
end
application_controllerで何か間違ったことをしていると思われます。
更新 2:
だから私は3つの異なる方法を試しましたが、Google Chrome以外はすべてリクエストを1回行いました。これが既知の問題かどうかはわかりませんが、正しい方向に向けてくれたコメンターに感謝します。
更新 3:
この関連するバグを見つけましたhttp://code.google.com/p/chromium/issues/detail?id=39402
ファビコンを提供する以外に、これを回避する方法はありますか?