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

1.5k Views Asked by At

I'm working with a rails application I've been using for a very long time that has not had a front end prior to this point. By long time I mean over a year. I use it to run console-based database stuff.

I'm trying to put a simple front-end on it now, a json api, but have been unsuccessful so far because of this error when trying to visit the homepage, users#index, or localhost:3000. Here is the error (including the webrick startup information because there are some warnings):

    => 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)>'

Here is my Gemfile. I've frozen my rails version due to new versions of rails breaking some of my code.

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'

Here is my routes.rb file, pretty vanilla:

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

I've checked out similar error messages to this on SO but haven't found anything quite like my situation, i.e. a situation where everything is so vanilla/default.

I'm thinking the error is having to do with some code getting inherited or mixed (monkey-patched) in with ActionController somewhere in my massive codebase. However, all of the monkey-patches I've done that I know of are in my initializers folder, and I've temporarily removed that and still got the error.

Let me know what additional information you need and I'll provide it. Thanks

Additional Information

  • I'm using rails s to start the server

Here's my application.rb file

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

And since I'm always in development mode, here's my development.rb file

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

Here's is the full trace of the bug:

    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'

I added config.eager_load = true to application.rb and got an immediate crash when trying to start the server before I even tried to visit the homepage. Here's the stack trace for that.

    => 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>'
1

There are 1 best solutions below

0
On BEST ANSWER

Please check that your helpers in app/helpers folder are all modules not classes, example:

app/helpers/application_helper.rb should be:

module ApplicationHelper
end

not

class ApplicationHelper
end

Also if you're including something in your classes Concern for example it should be defined as a module not class