尝试访问网页时 rails 中的 ApplicationController 错误 -- 参数类型错误 Class(需要模块)

ApplicationController error in rails when trying to visit web page -- wrong argument type Class (module expected)

我正在使用我已经使用了很长时间的 rails 应用程序,在此之前它没有前端。很长一段时间我的意思是超过一年。我用它来 运行 基于控制台的数据库。

我现在正在尝试在上面放一个简单的前端,一个json api,但是由于在尝试访问主页时出现这个错误,到目前为止一直没有成功,用户#index,或 localhost:3000。这是错误(包括 webrick 启动信息,因为有一些警告):

    => Booting WEBrick
    => Rails 4.0.0 application starting in development on http://0.0.0.0:3000
    => Run `rails server -h` for more startup options
    => Ctrl-C to shutdown server
    config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly:

      * development - set it to false
      * test - set it to false (unless you use a tool that preloads your test environment)
      * production - set it to true

    [2015-08-06 10:38:59] INFO  WEBrick 1.3.1
    [2015-08-06 10:38:59] INFO  ruby 2.2.1 (2015-02-26) [x86_64-darwin14]
    [2015-08-06 10:38:59] INFO  WEBrick::HTTPServer#start: pid=2842 port=3000
    DEPRECATION WARNING: You didn't set config.secret_key_base. Read the upgrade documentation to learn more about this new config option. (called from service at /Users/daviddouglas/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:138)


    Started GET "/" for 127.0.0.1 at 2015-08-06 10:39:01 -0400

    TypeError (wrong argument type Class (expected Module)):
      app/controllers/application_controller.rb:1:in `<top (required)>'
      app/controllers/users_controller.rb:1:in `<top (required)>'

这是我的 Gemfile。由于 rails 的新版本破坏了我的一些代码,我已经冻结了我的 rails 版本。

source 'https://rubygems.org'

gem 'nori' #XML TO JSON
gem 'rubillow'

gem 'rails', '4.0.0' #locked version May 25, 2015
gem 'protected_attributes'


## activerecord etc
  gem 'pg'
  gem 'activerecord-postgis-adapter'
  gem 'squeel', '1.2.3'
  gem 'rgeo', '0.3.20' #locked version May 25, 2015
  gem 'nice-ffi'
  gem 'rgeo-shapefile', '0.2.3' #locked version May 25, 2015
  gem 'rgeo-geojson', '0.3.1' #locked version May 25, 2015
  gem 'geocoder', :git => "https://github.com/ddd1600/geocoder.git"
  gem 'georuby' #for parsing kml
## command line related
  gem 'highline'
  gem 'awesome_print'

这是我的 routes.rb 文件,非常普通:

PostgisRails::Application.routes.draw do
  #resources :users
  root :to => "users#index"
end

我已经在 SO 上查看了与此类似的错误消息,但没有发现任何与我的情况非常相似的信息,即一切都是如此的情况 vanilla/default。

我认为这个错误与我庞大的代码库中某处的 ActionController 继承或混合(猴子修补)的代码有关。但是,我知道的所有我做过的猴子补丁都在我的初始化文件夹中,我暂时删除了它,但仍然出现错误。

让我知道您需要什么额外信息,我会提供。谢谢

附加信息

这是我的 application.rb 文件

require File.expand_path('../boot', __FILE__)

require 'rails/all'
require 'highline/import'
require 'active_record/connection_adapters/postgis_adapter/railtie'

if defined?(Bundler)
  Bundler.require(*Rails.groups(:assets => %w(development test)))
end

module PostgisRails
  class Application < Rails::Application
    config.autoload_paths += Dir["#{config.root}/lib/**/"]
    config.autoload_paths += Dir["#{config.root}/app/modules/**/"]
    config.autoload_paths += Dir["#{config.root}/app/_misc/*.rb"]    
    config.encoding = "utf-8"
    config.filter_parameters += [:password]
    config.active_support.escape_html_entities_in_json = true
    config.active_record.whitelist_attributes = true
    config.assets.enabled = true
    config.assets.version = '1.0'
  end
end

因为我一直处于开发模式,所以这是我的 development.rb 文件

PostgisRails::Application.configure do
  config.cache_classes = false
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false
  config.action_mailer.raise_delivery_errors = false
  config.active_support.deprecation = :log
  config.action_dispatch.best_standards_support = :builtin
  config.assets.compress = false
  config.assets.debug = true
end

这是该错误的完整踪迹:

    actionpack (4.0.0) lib/abstract_controller/helpers.rb:165:in `include'
    actionpack (4.0.0) lib/abstract_controller/helpers.rb:165:in `block in add_template_helper'
    actionpack (4.0.0) lib/abstract_controller/helpers.rb:165:in `module_eval'
    actionpack (4.0.0) lib/abstract_controller/helpers.rb:165:in `add_template_helper'
    actionpack (4.0.0) lib/abstract_controller/helpers.rb:95:in `block in helper'
    actionpack (4.0.0) lib/abstract_controller/helpers.rb:94:in `each'
    actionpack (4.0.0) lib/abstract_controller/helpers.rb:94:in `helper'
    actionpack (4.0.0) lib/action_controller/railties/helpers.rb:17:in `inherited'
    app/controllers/application_controller.rb:1:in `<top (required)>'
    activesupport (4.0.0) lib/active_support/dependencies.rb:423:in `load'
    activesupport (4.0.0) lib/active_support/dependencies.rb:423:in `block in load_file'
    activesupport (4.0.0) lib/active_support/dependencies.rb:615:in `new_constants_in'
    activesupport (4.0.0) lib/active_support/dependencies.rb:422:in `load_file'
    activesupport (4.0.0) lib/active_support/dependencies.rb:323:in `require_or_load'
    activesupport (4.0.0) lib/active_support/dependencies.rb:462:in `load_missing_constant'
    activesupport (4.0.0) lib/active_support/dependencies.rb:183:in `const_missing'
    app/controllers/users_controller.rb:1:in `<top (required)>'
    activesupport (4.0.0) lib/active_support/dependencies.rb:423:in `load'
    activesupport (4.0.0) lib/active_support/dependencies.rb:423:in `block in load_file'
    activesupport (4.0.0) lib/active_support/dependencies.rb:615:in `new_constants_in'
    activesupport (4.0.0) lib/active_support/dependencies.rb:422:in `load_file'
    activesupport (4.0.0) lib/active_support/dependencies.rb:323:in `require_or_load'
    activesupport (4.0.0) lib/active_support/dependencies.rb:462:in `load_missing_constant'
    activesupport (4.0.0) lib/active_support/dependencies.rb:183:in `const_missing'
    activesupport (4.0.0) lib/active_support/inflector/methods.rb:226:in `const_get'
    activesupport (4.0.0) lib/active_support/inflector/methods.rb:226:in `block in constantize'
    activesupport (4.0.0) lib/active_support/inflector/methods.rb:224:in `each'
    activesupport (4.0.0) lib/active_support/inflector/methods.rb:224:in `inject'
    activesupport (4.0.0) lib/active_support/inflector/methods.rb:224:in `constantize'
    activesupport (4.0.0) lib/active_support/dependencies.rb:534:in `get'
    activesupport (4.0.0) lib/active_support/dependencies.rb:565:in `constantize'
    actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:76:in `controller_reference'
    actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:66:in `controller'
    actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:44:in `call'
    actionpack (4.0.0) lib/action_dispatch/journey/router.rb:71:in `block in call'
    actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `each'
    actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `call'
    actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:655:in `call'
    rack (1.5.3) lib/rack/etag.rb:23:in `call'
    rack (1.5.3) lib/rack/conditionalget.rb:25:in `call'
    rack (1.5.3) lib/rack/head.rb:11:in `call'
    actionpack (4.0.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
    actionpack (4.0.0) lib/action_dispatch/middleware/flash.rb:241:in `call'
    rack (1.5.3) lib/rack/session/abstract/id.rb:225:in `context'
    rack (1.5.3) lib/rack/session/abstract/id.rb:220:in `call'
    actionpack (4.0.0) lib/action_dispatch/middleware/cookies.rb:486:in `call'
    activerecord (4.0.0) lib/active_record/query_cache.rb:36:in `call'
    activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
    actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
    activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__338496911207587002__call__callbacks'
    activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
    actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
    actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:64:in `call'
    actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
    actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
    actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
    railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
    railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
    activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
    activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
    activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
    railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
    actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
    rack (1.5.3) lib/rack/methodoverride.rb:21:in `call'
    rack (1.5.3) lib/rack/runtime.rb:17:in `call'
    activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
    rack (1.5.3) lib/rack/lock.rb:17:in `call'
    actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in `call'
    railties (4.0.0) lib/rails/engine.rb:511:in `call'
    railties (4.0.0) lib/rails/application.rb:97:in `call'
    rack (1.5.3) lib/rack/lock.rb:17:in `call'
    rack (1.5.3) lib/rack/content_length.rb:14:in `call'
    rack (1.5.3) lib/rack/handler/webrick.rb:60:in `service'
    /Users/daviddouglas/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
    /Users/daviddouglas/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
    /Users/daviddouglas/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'

我将 config.eager_load = true 添加到 application.rb,但在尝试访问主页之前尝试启动服务器时立即崩溃。这是它的堆栈跟踪。

    => Booting WEBrick
    => Rails 4.0.0 application starting in development on http://0.0.0.0:3000
    => Run `rails server -h` for more startup options
    => Ctrl-C to shutdown server
    Exiting
    /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/actionpack-4.0.0/lib/abstract_controller/helpers.rb:165:in `include': wrong argument type Class (expected Module) (TypeError)
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/actionpack-4.0.0/lib/abstract_controller/helpers.rb:165:in `block in add_template_helper'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/actionpack-4.0.0/lib/abstract_controller/helpers.rb:165:in `module_eval'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/actionpack-4.0.0/lib/abstract_controller/helpers.rb:165:in `add_template_helper'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/actionpack-4.0.0/lib/abstract_controller/helpers.rb:95:in `block in helper'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/actionpack-4.0.0/lib/abstract_controller/helpers.rb:94:in `each'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/actionpack-4.0.0/lib/abstract_controller/helpers.rb:94:in `helper'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/actionpack-4.0.0/lib/action_controller/railties/helpers.rb:17:in `inherited'
        from /Users/daviddouglas/Develop/postgis_rails/app/controllers/application_controller.rb:1:in `<top (required)>'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:423:in `load'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:423:in `block in load_file'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:615:in `new_constants_in'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:422:in `load_file'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:323:in `require_or_load'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:288:in `depend_on'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:206:in `require_dependency'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/railties-4.0.0/lib/rails/engine.rb:465:in `block (2 levels) in eager_load!'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/railties-4.0.0/lib/rails/engine.rb:464:in `each'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/railties-4.0.0/lib/rails/engine.rb:464:in `block in eager_load!'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/railties-4.0.0/lib/rails/engine.rb:462:in `each'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/railties-4.0.0/lib/rails/engine.rb:462:in `eager_load!'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/railties-4.0.0/lib/rails/engine.rb:347:in `eager_load!'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/railties-4.0.0/lib/rails/application/finisher.rb:56:in `each'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/railties-4.0.0/lib/rails/application/finisher.rb:56:in `block in <module:Finisher>'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `instance_exec'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `run'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/railties-4.0.0/lib/rails/initializable.rb:55:in `block in run_initializers'
        from /Users/daviddouglas/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each'
        from /Users/daviddouglas/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
        from /Users/daviddouglas/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:429:in `each_strongly_connected_component_from'
        from /Users/daviddouglas/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component'
        from /Users/daviddouglas/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:345:in `each'
        from /Users/daviddouglas/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:345:in `call'
        from /Users/daviddouglas/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component'
        from /Users/daviddouglas/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each'
        from /Users/daviddouglas/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:203:in `tsort_each'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/railties-4.0.0/lib/rails/initializable.rb:54:in `run_initializers'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/railties-4.0.0/lib/rails/application.rb:215:in `initialize!'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
        from /Users/daviddouglas/Develop/postgis_rails/config/environment.rb:5:in `<top (required)>'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
        from /Users/daviddouglas/Develop/postgis_rails/config.ru:3:in `block in <main>'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/rack-1.5.3/lib/rack/builder.rb:55:in `instance_eval'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/rack-1.5.3/lib/rack/builder.rb:55:in `initialize'
        from /Users/daviddouglas/Develop/postgis_rails/config.ru:in `new'
        from /Users/daviddouglas/Develop/postgis_rails/config.ru:in `<main>'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/rack-1.5.3/lib/rack/builder.rb:49:in `eval'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/rack-1.5.3/lib/rack/builder.rb:49:in `new_from_string'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/rack-1.5.3/lib/rack/builder.rb:40:in `parse_file'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/rack-1.5.3/lib/rack/server.rb:277:in `build_app_and_options_from_config'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/rack-1.5.3/lib/rack/server.rb:199:in `app'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/railties-4.0.0/lib/rails/commands/server.rb:48:in `app'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/rack-1.5.3/lib/rack/server.rb:314:in `wrapped_app'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/railties-4.0.0/lib/rails/commands/server.rb:75:in `start'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/railties-4.0.0/lib/rails/commands.rb:78:in `block in <top (required)>'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/railties-4.0.0/lib/rails/commands.rb:73:in `tap'
        from /Users/daviddouglas/.rvm/gems/ruby-2.2.1/gems/railties-4.0.0/lib/rails/commands.rb:73:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'

请检查 app/helpers 文件夹中的助手是否都是非 class 模块,例如:

app/helpers/application_helper.rb 应该是:

module ApplicationHelper
end

不是

class ApplicationHelper
end

此外,如果您在 classes Concern 中包含某些内容,例如它应该被定义为模块而不是 class