1

我有一个奇怪的问题,任何获取请求都被调用了两次。这是日志输出

第一次通话

Started GET "/admin/dashboard" for 127.0.0.1 at 2013-02-14 17:42:33 -0500
Processing by Admin::DashboardController#index as HTML

紧接着第二个电话

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 调用也在进行数据库查询。

更新:添加控制器输出

这是我的管理员/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:

发现这个相关的错误http://code.google.com/p/chromium/issues/detail?id=39402

除了提供网站图标之外,还有其他方法吗?

4

0 回答 0