Rails路由失败

时间:2015-12-07 07:58:50

标签: ruby-on-rails

我们的Rails应用程序中的路径突然 none 正在运行。

我试图离开Heroku,我的代码在那里工作愉快,完全无法在新环境中路由。

我的堆栈跟踪是:

ActionController::RoutingError (No route matches [GET] "/"):
  actionpack (4.0.13) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (4.0.13) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.0.13) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.0.13) lib/rails/rack/logger.rb:22:in `call'
  actionpack (4.0.13) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.5) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.5) lib/rack/runtime.rb:17:in `call'
  activesupport (4.0.13) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
  actionpack (4.0.13) lib/action_dispatch/middleware/static.rb:84:in `call'
  rack (1.5.5) lib/rack/deflater.rb:25:in `call'
  rack (1.5.5) lib/rack/sendfile.rb:112:in `call'
  airbrake (4.1.0) lib/airbrake/user_informer.rb:16:in `_call'
  airbrake (4.1.0) lib/airbrake/user_informer.rb:12:in `call'
  railties (4.0.13) lib/rails/engine.rb:511:in `call'
  railties (4.0.13) lib/rails/application.rb:97:in `call'
  rack-reverse-proxy (0.4.4) lib/rack/reverse_proxy.rb:16:in `call'
  rack (1.5.5) lib/rack/content_length.rb:14:in `call'
  puma (2.11.1) lib/puma/server.rb:507:in `handle_request'
  puma (2.11.1) lib/puma/server.rb:375:in `process_client'
  puma (2.11.1) lib/puma/server.rb:262:in `block in run'
  puma (2.11.1) lib/puma/thread_pool.rb:104:in `call'
  puma (2.11.1) lib/puma/thread_pool.rb:104:in `block in spawn_thread'

但我没有得到任何关于问题原因的线索。

rake route显示路径:

bundle exec rake routes
...
root GET    /                   sessions#new
...

我预计会有一些问题成为移动过程的一部分,但是没想到任何与路由相关的问题。我尝试过使用webrick而不是puma,并没有任何区别。我还尝试了许多不同的路线,这些路线出现在rake routes中,而且我尝试过的路线都没有。我此时有点难过。我该怎么做才能进一步调查这个问题?

新环境是Debian Jessie。

更新

routes.rb文件的一部分:

AltApp::Application.routes.draw do
  post "/client/fargo/initiate"
  post "/", to: "client/fargo#initiate"
  get '/users/sign_in', to: redirect('/')

  constraints DomainConstraint.new([DOMAIN_NAMES[:company][Rails.env], DOMAIN_NAMES[:alternate][Rails.env]]) do
    devise_for :users, :skip => [:registrations], :controllers => {:sessions => "sessions", :passwords => "passwords"}

    devise_scope :user do
      root :to => 'sessions#new'
    end

    namespace :admin do
      resources :invites, only: :index

      resources :companies, only: [:edit, :update, :destroy, :index] do
        member do
          patch :toggle_activate
        end

        collection do
          patch :bulk_operations
          get :autocomplete_company_name
        end

        resources :notes, :only => [:index, :create]
      end

      resources :reports, :only => [] do
        collection do
          get 'type/:report_type', :to => :index, :as => '', :constraints => { :report_type => /(billing|survey_support|weekly_report)/i }
          get 'social/:report_type', :to => :social, :as => 'social', :constraints => { :report_type => /(company|alternate)/ }
          get 'cgp/:report_type', :to => :cgp, :as => 'cgp', :constraints => { :report_type => /(people_match_score)/i }
          get 'miscellaneous/:report_type', :to => :miscellaneous, :as => 'miscellaneous', :constraints => { :report_type => /(participant_characteristics|participant_characteristics_count)/i }
          get :mail_database_csv
        end
      end

      resources :users, :only => [:new, :edit, :update, :destroy] do
        resources :notes, :only => [:index, :create]
        patch :toggle_activate, :on => :member
      end

      resources :participants, only: [:update] do
        collection do
          get :autocomplete_participant_email
        end
      end
    end

    resources :inquiries, :only => :create
    resources :invites, :only => :create
  end

...

更新2

我们在现有的heroku环境中使用https,但我还没有在新环境中进行设置。

更新3

我怀疑它与我们拥有的机架中间件有关。

我在代码中注释了它,路由正在运行。它仍然不清楚我为什么或如何打破路线。另外,为什么它不会出现在堆栈跟踪中。

它似乎不是中间件。

1 个答案:

答案 0 :(得分:1)

错误很明显:

No route matches [GET] "/"

这意味着您的路线存在某种不匹配。也就是说,您似乎没有声明root路径,我知道您尝试路由到devise

-

我要说的主要问题是你使用DOMAIN_NAME约束。你为什么得到它......当然只有你的网站才能从域名访问?

AltApp::Application.routes.draw do
  root to: "application#landing" # may fix your error but will be a monkey patch

  post "/client/fargo/initiate"
  post "/", to: "client/fargo#initiate"

  constraints DomainConstraint.new([DOMAIN_NAMES[:company][Rails.env], DOMAIN_NAMES[:alternate][Rails.env]]) do
    devise_for :users, path: "", skip: [:registrations], controllers: {sessions: "sessions", passwords: "passwords"}, path_names: { sign_in: "" }

    namespace :admin do
      ....
    end

    resources :inquiries, :invites, only: :create
  end

我认为底线是你如何使你的DOMAIN_NAMES常数 - 如果你要转移到另一台服务器,也许传递的域名与Heroku不同?

目前,您的路线将依赖于特定的域名。如果您在顶部添加root to:(进行测试),那么应该为Rails提供一个“非域”路由来发送您的用户,您可以通过重构{{1}来构建使其与您的新域一起使用。