【问题标题】:Superclass mismatch for class User (TypeError)?类用户的超类不匹配(TypeError)?
【发布时间】:2013-12-13 23:32:56
【问题描述】:

我在使用 Heroku 时遇到了麻烦。我做了heroku logs 并收到一条错误消息:

/app/app/models/user.rb:1:in `<top (required)>': superclass mismatch for class User     (TypeError)

/app/app/models/user.rb:1:in `<top (required)>': superclass mismatch for class User     (TypeError)

2013-11-28T03:39:50.220378+00:00 app[web.1]:    from    
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-
3.2.11/lib/active_support/dependencies.rb:251:in `require'
2013-11-28T03:39:50.220378+00:00 app[web.1]:    from   
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-
3.2.11/lib/active_support/dependencies.rb:251:in `block in require'
2013-11-28T03:39:50.220378+00:00 app[web.1]:    from 
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-
3.2.11/lib/active_support/dependencies.rb:251:in `require'
2013-11-28T03:39:50.220378+00:00 app[web.1]:    from 
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-
3.2.11/lib/active_support/dependencies.rb:359:in `require_or_load'
2013-11-28T03:39:50.220378+00:00 app[web.1]:    from   
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-
3.2.11/lib/active_support/dependencies.rb:236:in `load_dependency'
2013-11-28T03:39:50.220378+00:00 app[web.1]:    from   
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-
3.2.11/lib/active_support/dependencies.rb:313:in `depend_on'
2013-11-28T03:39:50.220378+00:00 app[web.1]:    from 
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-
3.2.11/lib/active_support/dependencies.rb:225:in `require_dependency'
2013-11-28T03:39:50.220378+00:00 app[web.1]:    from 
/app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.11/lib/rails/engine.rb:438:in `each'
2013-11-28T03:39:50.220557+00:00 app[web.1]:    from 
/app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.11/lib/rails/engine.rb:436:in 
`eager_load!'
2013-11-28T03:39:50.220557+00:00 app[web.1]:    from   
/app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.11/lib/rails/engine.rb:438:in `block in 
eager_load!'
2013-11-28T03:39:50.220378+00:00 app[web.1]:    from 
/app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.11/lib/rails/engine.rb:439:in `block (2 
levels) in eager_load!'
2013-11-28T03:39:50.220557+00:00 app[web.1]:    from 
/app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.11/lib/rails/application/finisher.rb:53:in 
`block in <module:Finisher>'
2013-11-28T03:39:50.220557+00:00 app[web.1]:    from 
/app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.11/lib/rails/initializable.rb:30:in 
`instance_exec'
2013-11-28T03:39:50.220557+00:00 app[web.1]:    from 
/app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `run'
2013-11-28T03:39:50.220557+00:00 app[web.1]:    from 
/app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.11/lib/rails/engine.rb:436:in `each'
2013-11-28T03:39:50.220557+00:00 app[web.1]:    from 
/app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `each'
2013-11-28T03:39:50.220557+00:00 app[web.1]:    from 
/app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.11/lib/rails/initializable.rb:54:in 
`run_initializers'
2013-11-28T03:39:50.220696+00:00 app[web.1]:    from 
/app/vendor/bundle/ruby/2.0.0/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize'
2013-11-28T03:39:50.220557+00:00 app[web.1]:    from 
/app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.11/lib/rails/application.rb:136:in 
`initialize!'
2013-11-28T03:39:50.220696+00:00 app[web.1]:    from /app/config/environment.rb:5:in 
`<top (required)>'
2013-11-28T03:39:50.220696+00:00 app[web.1]:    from /app/config.ru:in `<main>'
2013-11-28T03:39:50.220696+00:00 app[web.1]:    from /app/config.ru:3:in `require'
2013-11-28T03:39:50.220557+00:00 app[web.1]:    from 
/app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.11/lib/rails/initializable.rb:55:in `block   
in run_initializers'
2013-11-28T03:39:50.220696+00:00 app[web.1]:    from   
/app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.11/lib/rails/railtie/configurable.rb:30:in 
`method_missing'
2013-11-28T03:39:50.220696+00:00 app[web.1]:    from 
/app/vendor/bundle/ruby/2.0.0/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval'
2013-11-28T03:39:50.220696+00:00 app[web.1]:    from 
/app/vendor/bundle/ruby/2.0.0/gems/rack-1.4.5/lib/rack/builder.rb:40:in `eval'
2013-11-28T03:39:50.220696+00:00 app[web.1]:    from /app/config.ru:in `new'
2013-11-28T03:39:50.221093+00:00 app[web.1]:    from 
/app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.11/lib/rails/commands/server.rb:70:in 
`start' 
2013-11-28T03:39:50.220696+00:00 app[web.1]:    from 
/app/vendor/bundle/ruby/2.0.0/gems/rack-1.4.5/lib/rack/builder.rb:40:in `parse_file'
2013-11-28T03:39:50.221093+00:00 app[web.1]:    from 
/app/vendor/bundle/ruby/2.0.0/gems/rack-1.4.5/lib/rack/server.rb:304:in `wrapped_app'
2013-11-28T03:39:50.221093+00:00 app[web.1]:    from 
/app/vendor/bundle/ruby/2.0.0/gems/rack-1.4.5/lib/rack/server.rb:200:in `app'
2013-11-28T03:39:50.220696+00:00 app[web.1]:    from /app/config.ru:3:in `block in 
<main>'
2013-11-28T03:39:50.221093+00:00 app[web.1]:    from   
/app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.11/lib/rails/commands/server.rb:46:in `app'
2013-11-28T03:39:50.221093+00:00 app[web.1]:    from 
/app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.11/lib/rails/commands.rb:50:in `tap'
2013-11-28T03:39:50.221093+00:00 app[web.1]:    from   
/app/vendor/bundle/ruby/2.0.0/gems/rack-1.4.5/lib/rack/server.rb:254:in `start'
2013-11-28T03:39:50.221093+00:00 app[web.1]:    from  
/app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.11/lib/rails/commands.rb:55:in `block in 
<top (required)>'
2013-11-28T03:39:50.221093+00:00 app[web.1]:    from   
/app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.11/lib/rails/commands.rb:50:in `<top 
(required)>'
2013-11-28T03:39:50.221093+00:00 app[web.1]:    from script/rails:6:in `require'
2013-11-28T03:39:50.221093+00:00 app[web.1]:    from script/rails:6:in `<main>'
2013-11-28T03:39:51.352167+00:00 heroku[web.1]: Process exited with status 1
2013-11-28T03:39:51.375056+00:00 heroku[web.1]: State changed from starting to crashed

我不明白为什么会出现此错误,因为我没有 /models/user.rb/。是的。我实际上做了一次并删除了它。

你能给我一些建议吗?

【问题讨论】:

  • 您是否承诺删除它并推动该更改?

标签: ruby-on-rails ruby ruby-on-rails-3 heroku


【解决方案1】:

对于那些将来阅读本文的人:这是一个潜在的解决方案:

潜在原因是什么?

很可能,在您的代码的某个地方,您已经两次定义了同一个类。在这种特殊情况下,也许class User 两次 - 在两个不同的地方定义。在我的特殊情况下,我在测试代码库的两个不同位置有相同的类和相同的文件名。也许你的情况是一样的?运行一个快速的 grep 来检查可能是值得的。希望对您有所帮助。

【讨论】:

    【解决方案2】:

    我确信这个问题对你来说并不现实。但是对于将在这里寻找解决方案的人,我只想提一个可能的原因。 在遵循 Michael Hartl 的“Rails Tutorial”时,我遇到了这样的错误。就我而言,这是我的疏忽——我将文件 example_user.rb (来自4.4.5 A user class 章)不是在应用程序的根目录中,而是在控制器文件夹中。在我解决了这个问题之后——Heroku 的问题就消失了。

    【讨论】:

      【解决方案3】:

      看看

      /app/app/models/user.rb
      

      应用程序/应用程序?这是关闭的。调查您的项目来源,您确实有一个 user.rb 文件

      【讨论】:

      • /app 是 Heroku 根目录,所以 /app/app 是你项目的 app 文件夹。
      • 谢谢 ThelrishGuy 先生,我设法解决了这个问题。我只是忘记在 git 上暂存一些已删除的文件。所以,我不仅在本地删除了已删除的文件,而且在 git 上删除了文件。
      • 感谢您的建议,七海猫先生。
      猜你喜欢
      • 2018-03-10
      • 2017-11-03
      • 2016-02-24
      • 1970-01-01
      • 2021-12-29
      • 1970-01-01
      • 2022-11-03
      • 2022-01-18
      • 1970-01-01
      相关资源
      最近更新 更多