2017-09-21 67 views
0

獲取可怕的路由錯誤。在Win10上運行的Ubuntu 16.04。 Rails 2.4.1。使用崇高。Rails:未初始化的常量WelcomeController路由錯誤

的routes.rb:

Rails.application.routes.draw do 

    get "welcome/home", to: "welcome#home" 

end 

我有一個welcome_controller.rb(在app /控制器):

class WelcomeController < ApplicationController 

end 

在這裏試穿左右,但相當多的解決方案似乎無法得到這個工作。注意:每次更改後我都會重新啓動導軌,以查看更改。 我可以做額外的日誌記錄嗎?不同的代碼?

Full Trace: 
activesupport (5.1.4) lib/active_support/inflector/methods.rb:269:in `const_get' 
activesupport (5.1.4) lib/active_support/inflector/methods.rb:269:in `block in constantize' 
activesupport (5.1.4) lib/active_support/inflector/methods.rb:267:in `each' 
activesupport (5.1.4) lib/active_support/inflector/methods.rb:267:in `inject' 
activesupport (5.1.4) lib/active_support/inflector/methods.rb:267:in `constantize' 
actionpack (5.1.4) lib/action_dispatch/http/request.rb:85:in `controller_class_for' 
actionpack (5.1.4) lib/action_dispatch/http/request.rb:78:in `controller_class' 
actionpack (5.1.4) lib/action_dispatch/routing/route_set.rb:43:in `controller' 
actionpack (5.1.4) lib/action_dispatch/routing/route_set.rb:29:in `serve' 
actionpack (5.1.4) lib/action_dispatch/journey/router.rb:50:in `block in serve' 
actionpack (5.1.4) lib/action_dispatch/journey/router.rb:33:in `each' 
actionpack (5.1.4) lib/action_dispatch/journey/router.rb:33:in `serve' 
actionpack (5.1.4) lib/action_dispatch/routing/route_set.rb:834:in `call' 
rack (2.0.3) lib/rack/etag.rb:25:in `call' 
rack (2.0.3) lib/rack/conditional_get.rb:25:in `call' 
rack (2.0.3) lib/rack/head.rb:12:in `call' 
rack (2.0.3) lib/rack/session/abstract/id.rb:232:in `context' 
rack (2.0.3) lib/rack/session/abstract/id.rb:226:in `call' 
actionpack (5.1.4) lib/action_dispatch/middleware/cookies.rb:613:in `call' 
activerecord (5.1.4) lib/active_record/migration.rb:556:in `call' 
actionpack (5.1.4) lib/action_dispatch/middleware/callbacks.rb:26:in `block in call' 
activesupport (5.1.4) lib/active_support/callbacks.rb:97:in `run_callbacks' 
actionpack (5.1.4) lib/action_dispatch/middleware/callbacks.rb:24:in `call' 
actionpack (5.1.4) lib/action_dispatch/middleware/executor.rb:12:in `call' 
actionpack (5.1.4) lib/action_dispatch/middleware/debug_exceptions.rb:59:in `call' 
web-console (3.5.1) lib/web_console/middleware.rb:135:in `call_app' 
web-console (3.5.1) lib/web_console/middleware.rb:28:in `block in call' 
web-console (3.5.1) lib/web_console/middleware.rb:18:in `catch' 
web-console (3.5.1) lib/web_console/middleware.rb:18:in `call' 
actionpack (5.1.4) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call' 
railties (5.1.4) lib/rails/rack/logger.rb:36:in `call_app' 
railties (5.1.4) lib/rails/rack/logger.rb:24:in `block in call' 
activesupport (5.1.4) lib/active_support/tagged_logging.rb:69:in `block in tagged' 
activesupport (5.1.4) lib/active_support/tagged_logging.rb:26:in `tagged' 
activesupport (5.1.4) lib/active_support/tagged_logging.rb:69:in `tagged' 
railties (5.1.4) lib/rails/rack/logger.rb:24:in `call' 
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call' 
actionpack (5.1.4) lib/action_dispatch/middleware/remote_ip.rb:79:in `call' 
actionpack (5.1.4) lib/action_dispatch/middleware/request_id.rb:25:in `call' 
rack (2.0.3) lib/rack/method_override.rb:22:in `call' 
rack (2.0.3) lib/rack/runtime.rb:22:in `call' 
activesupport (5.1.4) lib/active_support/cache/strategy/local_cache_middleware.rb:27:in `call' 
actionpack (5.1.4) lib/action_dispatch/middleware/executor.rb:12:in `call' 
actionpack (5.1.4) lib/action_dispatch/middleware/static.rb:125:in `call' 
rack (2.0.3) lib/rack/sendfile.rb:111:in `call' 
railties (5.1.4) lib/rails/engine.rb:522:in `call' 
puma (3.10.0) lib/puma/configuration.rb:225:in `call' 
puma (3.10.0) lib/puma/server.rb:605:in `handle_request' 
puma (3.10.0) lib/puma/server.rb:437:in `process_client' 
puma (3.10.0) lib/puma/server.rb:301:in `block in run' 
puma (3.10.0) lib/puma/thread_pool.rb:120:in `block in spawn_thread' 

路線:

Prefix Verb URI Pattern    Controller#Action 
welcome_home GET /welcome/home(.:format) welcome#home 

application.rb中

require_relative 'boot' 

require 'rails/all' 

Bundler.require(*Rails.groups) 

module Mattsapp 
class Application < Rails::Application 

config.load_defaults 5.1 

end 
end 

Development.rb

Rails.application.configure do 

    config.cache_classes = false 

    config.eager_load = false 

    config.consider_all_requests_local = true 

    if Rails.root.join('tmp/caching-dev.txt').exist? 
    config.action_controller.perform_caching = true 

    config.cache_store = :memory_store 
    config.public_file_server.headers = { 
     'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}" 
    } 
    else 
    config.action_controller.perform_caching = false 

    config.cache_store = :null_store 
    end 

    config.action_mailer.raise_delivery_errors = false 

    config.action_mailer.perform_caching = false 

    config.active_support.deprecation = :log 

    config.active_record.migration_error = :page_load 

    config.assets.debug = true 

    config.assets.quiet = true 

    config.file_watcher = ActiveSupport::EventedFileUpdateChecker 
end 
+0

URL是:http:// localhost:3000/welcome/home/ – codeclimb

+0

發佈錯誤的堆棧跟蹤,因爲您在此處發佈的任何內容在技術上都是不正確的,除非您沒有定義的「home」方法'WelcomeController'但是不會引發你引用的錯誤 – engineersmnky

+0

@codeclimb,因爲你的歡迎控制器和你的home方法,爲什麼不在你的routes.rb文件中使用root'welcome#home' –

回答

0

試圖通過增加使你的路徑相對於根/前

get "/welcome/home", to: "welcome#home" 

,並添加家庭行動到控制器...

Class WelcomeController < ApplicationController 
    def home 
    end 
end 
+0

這並沒有幫助:( – codeclimb

+0

@codeclimb確保將home方法添加到您的控制器。 –

1

添加高清家用功能,讓它空你的welcome控制器。喜歡這個。如果你想讓它做些什麼,你可以添加它。但現在,請把它留空!

def home 
end 
0

的共識是,CONFIGS就在這裏(導軌),但有可能與Win10/Ubuntu的設置有問題。我不會再對此進行調查。如果我遇到一些問題,我會更新線程。

相關問題