Rails:未初始化的常量WelcomeController路由错误

时间:2017-09-21 17:51:12

标签: ruby-on-rails ruby

获得可怕的路由错误。 Ubuntu 16.04在Win10上运行。 Rails 2.4.1。使用Sublime。

routes.rb中:

Rails.application.routes.draw do

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

end

我有一个welcome_controller.rb(在app / controllers中):

class WelcomeController < ApplicationController

end

在SO上尝试了很多解决方案,但似乎无法实现这一点。注意:每次更改后我都会重新启动rails以查看更改。 我可以做的其他日志记录?不同的代码?

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

3 个答案:

答案 0 :(得分:1)

添加def home功能并在欢迎控制器中将其留空。像这样。如果你想要它做某事,你可以加入它。但是现在,请把它留空!

def home
end

答案 1 :(得分:0)

尝试通过在

之前添加/来使您的路径相对于root
  get "/welcome/home",  to: "welcome#home"

并向您的控制器添加主页操作...

 Class WelcomeController < ApplicationController
   def home
   end
 end

答案 2 :(得分:0)

共识是配置就在这里(rails),但可能是Win10 / Ubuntu设置的问题。我不会再进一步​​调查。如果我遇到了什么,我会更新线程。