首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >试图访问网页时rails中的ApplicationController错误--错误的参数类型类(模块期望)

试图访问网页时rails中的ApplicationController错误--错误的参数类型类(模块期望)
EN

Stack Overflow用户
提问于 2015-08-06 14:49:42
回答 1查看 1.4K关注 0票数 1

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

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

代码语言:javascript
复制
    => 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)>'

这是我的个人资料。由于新版本的rails破坏了一些代码,我冻结了rails版本。

代码语言:javascript
复制
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文件,非常普通:

代码语言:javascript
复制
PostgisRails::Application.routes.draw do
  #resources :users
  root :to => "users#index"
end

我已经检查了与此类似的错误消息,但是没有发现任何类似于我的情况,即所有东西都很普通/默认的情况。

我认为这个错误与某些代码被继承或混合(猴子补丁)到我庞大的代码库中的某个地方的ActionController有关。但是,我所知道的所有猴子补丁都在我的初始值文件夹中,我暂时删除了它,但仍然得到了错误。

告诉我你需要什么额外的信息,我会提供的。谢谢

更多信息

  • 我使用rails s启动服务器

这是我的application.rb文件

代码语言:javascript
复制
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文件

代码语言:javascript
复制
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

下面是bug的全部跟踪信息:

代码语言:javascript
复制
    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中,在尝试访问主页之前,我尝试启动服务器时立即崩溃。这是它的堆栈跟踪。

代码语言:javascript
复制
    => 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>'
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-22 16:06:18

请检查app/helpers文件夹中的帮助程序是否都是模块,而不是类,例如:

app/helpers/application_helper.rb应为:

代码语言:javascript
复制
module ApplicationHelper
end

代码语言:javascript
复制
class ApplicationHelper
end

另外,如果您在类中包含了某些内容,例如,Concern,则应该将其定义为模块,而不是类

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31858948

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档