Rails 3.2.x路由被调用两次

时间:2013-02-14 22:47:39

标签: ruby-on-rails ruby

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

先致电

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

更新:添加控制器输出

这是我的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:

所以我尝试了三种不同的方法,但谷歌Chrome只提出了一次请求。我不知道这是否是一个已知的问题,但感谢评论者指出我正确的方向。

更新3:

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

除了提供一个favicon之外还有办法吗?

0 个答案:

没有答案