Rails路由在部署中中断

时间:2014-09-15 22:12:19

标签: ruby-on-rails

经过多年的开发,包括在Heroku上部署,我正在跟随Ryan Bates的Railscast部署到VPS(Linode)进行升级。一切顺利部署,独角兽启动,然后在我请求的任何路线上抛出错误,即(这是一个简单的页面#welcome请求):

Started GET "/welcome" for 108.74.161.183 at 2014-09-15 22:02:43 +0000

ActionController::RoutingError (No route matches [GET] "/welcome"):
  actionpack (4.0.3) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (4.0.3) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.0.3) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.0.3) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.0.3) lib/active_support/tagged_logging.rb:67:in `block in tagged'
  activesupport (4.0.3) lib/active_support/tagged_logging.rb:25:in `tagged'
  activesupport (4.0.3) lib/active_support/tagged_logging.rb:67:in `tagged'
  railties (4.0.3) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.0.3) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  activesupport (4.0.3) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
  actionpack (4.0.3) lib/action_dispatch/middleware/static.rb:64:in `call'
  rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
  railties (4.0.3) lib/rails/engine.rb:511:in `call'
  railties (4.0.3) lib/rails/application.rb:97:in `call'
  railties (4.0.3) lib/rails/railtie/configurable.rb:30:in `method_missing'
  unicorn (4.8.2) lib/unicorn/http_server.rb:573:in `process_client'
  unicorn (4.8.2) lib/unicorn/http_server.rb:667:in `worker_loop'
  unicorn (4.8.2) lib/unicorn/http_server.rb:522:in `spawn_missing_workers'
  unicorn (4.8.2) lib/unicorn/http_server.rb:533:in `maintain_worker_count'
  unicorn (4.8.2) lib/unicorn/http_server.rb:291:in `join'
  unicorn (4.8.2) bin/unicorn:126:in `<top (required)>'
  /var/www/RP/shared/bundle/ruby/1.9.1/bin/unicorn:23:in `load'
  /var/www/RP/shared/bundle/ruby/1.9.1/bin/unicorn:23:in `<main>'



***** Debugger requested, but was not available (ensure the debugger gem is listed in Gemfile/installed as gem): Start server with --debugger to enable *****

无论我是启动unicorn还是unicorn_rails,性能都是相同的。当我在服务器上运行“rake routes”时,它会尽职地列出它应该的所有路由。除了路由失败之外,我不明白的一件事是有关调试器请求的内容。我的代码中没有调试器调用,在/ app或/ lib中。但我没有看到调试器警告(之前从未出现问题)和路由故障之间存在任何关联。

我坐在这里撕扯我的头发,因为我无法想象这可能是什么问题的根源。非常感谢任何富有成效的建议。

的Gemfile:

source 'http://rubygems.org'

ruby '1.9.3'
gem 'rails', '~> 4.0' # '3.2.11' #
# gem 'rails',     :git => 'git://github.com/rails/rails.git'
# gem 'rails4_upgrade'
gem 'rails_12factor', :group => [ :production, :staging ]

# add these gems to help with the transition:
gem 'protected_attributes'
gem 'rails-observers'  
# gem 'actionpack-page_caching'
# gem 'actionpack-action_caching'

# Bundle edge Rails instead:

gem 'pg'

gem 'builder', '~> 3.1.0'
gem 'draper', '~> 1.3'
gem 'closure_tree'
gem 'htmlentities'
gem 'nokogiri', "~> 1.5" # "~> 1.5.3"
gem 'will_paginate', '~> 3.0'
gem 'newrelic_rpm'
gem 'devise', '~> 3.1.0'                       # auth, rails generate devise:install, rails generate devise MODEL
gem 'devise_invitable', '~> 1.3.0' # git: 'git://github.com/scambra/devise_invitable.git'
gem 'ruby-openid'
gem 'omniauth-twitter'                      
gem 'omniauth-facebook' # , '~> 1.4.0'
gem 'omniauth-google-oauth2'                     
gem 'omniauth-openid'                     
gem 'declarative_authorization'     # simple auth rules/roles, create config/authorization_rules.rb, add filter_resource_access to each controller, use permitted_to? in views
gem 'eventmachine', '~> 1.0.3'
gem 'ruby_parser'
gem "rmagick", "~> 2.13.2"
gem "feedzirra", "~> 0.2" # :git => 'git://github.com/pauldix/feedzirra.git'
gem "simple_form", :git => 'git://github.com/plataformatec/simple_form.git' # , '~> 3.0.0.beta1' 
gem 'delayed_job' # , git: 'git://github.com/collectiveidea/delayed_job.git'
gem 'delayed_job_active_record' # , git: 'git://github.com/collectiveidea/delayed_job_active_record.git'
gem 'daemons'
gem 'hirefire-resource'
# gem 'debugger', :group => [:test, :development]
gem 'awesome_nested_set'
gem 'redcarpet'
gem 'content_for_in_controllers'
gem 'youtube_addy'
# gem 'active_model_serializers'

gem 'exception_notification', git: 'git://github.com/smartinez87/exception_notification.git'
# gem 'exception_notification', '~> 4.0.1', :require => 'exception_notifier' # , git: 'git://github.com/alanjds/exception_notification.git' 
group :development do
  gem 'minitest', '~> 4.2'
  # gem 'rspec-rails'
  gem 'annotate', '2.5.0'
  gem "nifty-generators"
  gem 'log_buddy'
  gem 'ruby-prof', '~> 0.13.0' # , :git => 'git://github.com/wycats/ruby-prof.git'
  gem 'letter_opener'
  gem "better_errors"
  gem "binding_of_caller"
  # gem "json"
end

gem "masonry-rails"

group :test do
  gem 'minitest-rails', "~> 1.0" # gem 'minitest', '~> 4.2'
  # gem 'rspec-rails'
  # Pretty printed test output
  gem 'turn', :require => false
  gem 'webrat', '~> 0.7.3'
  gem "minitest-rails-capybara" # ...for simulating user interaction
  # gem "guard-rspec" # ...for auto-running tests on file save
  gem 'factory_girl_rails', "~> 4.0"
  gem "mocha"
  gem 'poltergeist'
end

gem 'coffee-rails', "~> 4.0.0"
gem 'uglifier', '>= 1.3.0'
# gem 'compass-rails'
gem 'sass-rails', " ~> 4.0"
gem 'bootstrap-sass', '~> 3.2.0' # '~> 3.1.1'
# gem 'bootstrap-sass', github: 'thomas-mcdonald/bootstrap-sass', branch: '3'
gem 'autoprefixer-rails'

gem 'jquery-rails'

# Use unicorn as the web server
gem 'unicorn'
gem 'unicorn-rails'

# Deploy with Capistrano
gem 'sshkit', '~> 1.3.0'
gem 'capistrano'
gem 'capistrano-rails'
gem 'capistrano-bundler'
gem 'capistrano-rbenv'
# gem 'capistrano-rvm'

routes.rb中:

  unless @RPRoutesLoaded
    @RPRoutesLoaded = true

    RP::Application.routes.draw do

      if Rails.env.development? || Rails.env.test?
        # IntegersController is for testing streams
        get "integers" => 'integers#index'
      end
      resources :votes, :only => :create
      post '/votes/recipes/:recipe_id' => 'votes#create', :as => "vote_recipe"
      get 'pic_picker/new' => 'pic_picker#new'

      get "redirect/go"
      get '/auth/failure' => 'authentications#failure'
      # get '/authentications/new' => 'authentications#new'
      resources :authentications

      devise_for :users, :skip => [ :registrations ], :controllers => {
          :sessions => 'sessions',
          :passwords => 'passwords',
          :invitations => 'invitations',
          # :registrations => 'registrations' # Had to elide this and use devise_scope to define /users/register instead of /users to create
      }

      match 'users', :controller=>'users', :action=>'index', :via => [:get, :post]

      devise_scope :user do
        post "/users/register" => "registrations#create", :as => "user_registration"
        get "/users/sign_up" => "registrations#new", :as => "new_user_registration"
        get "/users/edit" => "registrations#edit", :as => "edit_user_registration"
        get "/users/cancel" => "registrations#cancel", :as => "cancel_user_registration"
        put "/users" => "registrations#update"
        delete "/users" => "registrations#destroy"
        get "/users/sign_out" => "sessions#destroy"
        patch "/users" => "registrations#update"

        get "/users/invitation/divert" => "invitations#divert", :as => "divert_user_invitation"
      end

      get '/auth/:provider/callback' => 'authentications#create'
      post '/auth/:provider/callback' => 'authentications#create'

      # Calling 'profile' action in 'users' controller edits the current user
      get 'users/profile' => 'users#profile'
      # Ask a user to identify him/herself by email address
      get 'users/identify' => 'users#identify'
      get 'users/:id/recent' => 'users#recent'
      get 'users/:id/collection' => 'users#collection'
      get 'users/:id/biglist' => 'users#biglist'
      # get 'users/:id/show' => 'users#show'
      resources :users, :except => [ :index, :create ] do
        member do
          get 'collect'
          post 'remove'
          get 'match_friends'
          get 'notify'
          get 'acquire' # Acquire a recipe (etc.)
        end
      end

      post '/list' => 'lists#create', :as => 'create_list'
      resources :lists, except: [ :index, :create ] do
        member do
          get 'scrape'
        end
      end
      match 'lists', :controller=>'lists', :action=>'index', :via => [:get, :post]

      post '/site' => 'sites#create', :as => 'create_site'
      resources :sites, except: [ :index, :create ] do
        member do
          get 'scrape'
        end
      end
      match 'sites', :controller=>'sites', :action=>'index', :via => [:get, :post]

      post '/reference' => 'references#create', :as => 'create_reference'
      resources :references, :except => [ :index, :create ]
      match 'references', :controller=>'references', :action=>'index', :via => [:get, :post]

      post '/feed' => 'feeds#create', :as => 'create_feed'
      resources :feeds, :except => [ :index, :create ] do
        member do
          get 'collect' # Add the feed to the current user
          post 'remove' # Remove the feed from the current user's set
          post 'approve' # (Admin only) approve the feed for presentation
        end
      end
      match 'feeds', :controller=>'feeds', :action=>'index', :via => [:get, :post]

      post '/tag' => 'tags#create', :as => 'create_tag'
      resources :tags, except: [ :index, :create ] do
        member do
          post 'absorb'
        end
        collection do
          get 'editor'
          get 'list'
          get 'typify'
          get 'match'
        end
      end
      match 'tags', :controller=>'tags', :action=>'index', :via => [:get, :post]

      match 'collection', :controller=>'collection', :action=>'index', :via => [:get, :post]
      post 'collection/update'
      get "collection/refresh"
      get "collection/feed"
      get "collection/show", as: 'collection_show'
      get "collection/new"
      get "collection/edit"
      post "collection/create"
      get "collection/relist"

      get "stream/stream"
      get "stream/buffer_test"
      get "iframe/create"
      get "admin/data"
      get "admin/control"
      get "notifications/accept"

      resources :thumbnails
      resources :feedback, :only => [:new, :create]
      resources :expressions
      resources :referents
      resources :ratings
      resources :scales

      resources :recipes do
        resources :tags do
          member { post 'remove', :to => 'recipes#untag' }
        end
        member do
          get 'collect'
          get 'touch'
          get 'piclist'
          post 'remove'
        end
        collection do
          get 'capture'
          post 'parse'
        end
      end
      get '/revise', :to => 'recipes#revise'

      # get "pages/home"
      # get "pages/contact"
      # get "pages/about"
      get '/home', :to => 'pages#home'
      get '/popup/:name', :to => 'pages#popup'
      get '/popup', :to => 'pages#popup'
      get '/share', :to => 'pages#share'
      get '/contact', :to => 'pages#contact'
      get '/about', :to => 'pages#about'
      get '/welcome', :to => 'pages#welcome'
      get '/faq', :to=>"pages#faq"
      get '/admin', :to=>"pages#admin"
      get '/mobi', :to=>"pages#mobi"
      root :to => 'pages#root'
    end
  end

1 个答案:

答案 0 :(得分:3)

答案:似乎很久以前我试图通过使用一个标志来记住路由的加载,以防止在routes.rb中多次执行加载代码。出于某种原因,Rails决定在该标志的生命周期中重新加载它们两次,结果是第二次加载被阻止,导致......没有路由!这不是平台问题,而是环境问题,分期是唯一的受害环境。我不知道为什么路由会在分段中重新加载而不是在开发或生产中,但这是问题的根源。