agbodike
agbodike

Reputation: 1846

Rails Routes Failing

Suddenly none of the routes in our Rails app are working.

I'm attempting to move off Heroku, and my code that works happily there is entirely failing to route in the new environment.

my stack trace is:

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'

but I do not get any clues as to what is the cause of the problem.

rake route shows that path:

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

I expected a number of issues as part of the move process, but did not expect anything routing related. I've tried using just webrick rather than puma, and it made no difference. I've also tried a number of different routes that are showing up in rake routes, and none of the ones I've tried are working. I'm a bit stumped at this point. What can I do to further investigate this issue?

The new environment is Debian Jessie.

Update

Part of the routes.rb file:

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

...

Update 2

We are using https in our existing heroku environment, but I've not yet set it up in the new environment.

Update 3

I suspect it is related to a rack middleware that we have.

I commented it out of the code and the routes are working. It's still unclear to my why or how it is breaking the routes. Also, why it does not show up in the stack trace.

It doesn't appear to be the middleware.

Upvotes: 2

Views: 239

Answers (1)

Richard Peck
Richard Peck

Reputation: 76774

The error is clear:

No route matches [GET] "/"

This means that you've got some sort of mismatch with your routes. Namely, it would appear that you've not declared the root path, which I understand you're trying to route to devise.

--

I'd say the main problem is your use of the DOMAIN_NAME constraint. Why have you got it....surely only your site will be accessible from the domain?

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

I think the bottom line is how you're taking your DOMAIN_NAMES constant -- if you're moving to another server, perhaps the passed domain is different than Heroku?

At the moment, your routes will rely on a particular domain being present. If you add root to: at the top (to test), it should give Rails a "non domain" route to send your users to, which you can build upon by refactoring DomainConstraint to get it working with your new domain.

Upvotes: 1

Related Questions