为什么我在运行webrick服务器时会得到未初始化的常量设计名称错误?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了为什么我在运行webrick服务器时会得到未初始化的常量设计名称错误?相关的知识,希望对你有一定的参考价值。

在我的应用程序中,我使用了ruby 1.9.2和rails 3.0.3并且还安装了Devise gem。当我运行Webrick服务器时问题开始我得到了未初始化的常量设计名称错误。

       /home/app/Workspace/project/Library_Management/Library_Management/config/initializers/devise.rb:3:in `<top (required)>': uninitialized constant Devise (NameError)
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/engine.rb:201:in `block (2 levels) in <class:Engine>'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/engine.rb:200:in `each'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/engine.rb:200:in `block in <class:Engine>'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/initializable.rb:25:in `instance_exec'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/initializable.rb:25:in `run'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/initializable.rb:50:in `block in run_initializers'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/initializable.rb:49:in `each'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/initializable.rb:49:in `run_initializers'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/application.rb:134:in `initialize!'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/application.rb:77:in `method_missing'
from /home/app/Workspace/project/Library_Management/Library_Management/config/environment.rb:5:in `<top (required)>'
from /home/app/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:54:in `require'
from /home/app/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:54:in `require'
from /home/app/Workspace/project/Library_Management/Library_Management/config.ru:3:in `block in <main>'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/builder.rb:46:in `instance_eval'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/builder.rb:46:in `initialize'
from /home/app/Workspace/project/Library_Management/Library_Management/config.ru:1:in `new'
from /home/app/Workspace/project/Library_Management/Library_Management/config.ru:1:in `<main>'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/builder.rb:35:in `eval'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/builder.rb:35:in `parse_file'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/server.rb:162:in `app'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/server.rb:253:in `wrapped_app'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/server.rb:204:in `start'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands/server.rb:65:in `start'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands.rb:30:in `block in <top (required)>'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands.rb:27:in `tap'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands.rb:27:in `<top (required)>'
from /home/app/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:58:in `require'
from /home/app/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:58:in `rescue in require'
from /home/app/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require'

谢谢

答案

检查你的config / application.rb,你需要添加require'depaise',你应该没问题。

另一答案

在你的config / application.rb中添加require 'yaml'。这个对我有用。尝试

另一答案

如果您正在编写具有自己的设备配置的引擎,请添加

require 'devise'

在设计初始化器的开头。在我的情况下,我在应用程序中没有设计要求:)

干杯

另一答案

确保你已经在你的Gemfile中列出了Devise并运行bundle install

另一答案

我有一个错误,当我有一个自定义设计控制器来覆盖'新'方法来做一些自定义的东西,并忘了使用'超'

你有自定义控制器吗?

另一答案

我有一个类似的问题,我发现这个https://github.com/plataformatec/devise

它说你必须这样做

rails generate devise:install

在该页面上的“入门”后,我开始了

另一答案

如果你不再使用设计宝石,那么删除

gem 'devise'

来自gemfile和删除

config/initializers/devise.rb 

还要确保设备不在任何地方使用

另一答案

我只是遇到了这个问题,因为我错误地生成了一个视图模型而且我没有从routes.rb中删除它

另一答案

我不得不在spec / spec_helper.rb文件中添加require 'devise',并且该错误消失了。

另一答案

我安装Devise后添加了几列,我在用户模型中添加了一些验证。从错误消息,它看起来像铁路找不到必要的库因此它找不到Devise。也许签出Github设计Wiki页面并确保所有依赖项都满意?

希望能帮助到你!

以上是关于为什么我在运行webrick服务器时会得到未初始化的常量设计名称错误?的主要内容,如果未能解决你的问题,请参考以下文章

Webrick 的响应速度很慢。如何加快速度?

在 80 端口启动 webrick(mysql2 gem 问题)

在 Elastic Beanstalk 上部署 Rails 应用程序 - WEBrick 会自动被乘客取代吗?

如何设置 webrick 服务器以使用 ruby​​ 1.9.3?

Phusion 乘客诉 WEBrick

为什么当我更新二维数组时会出现“错误#1010”